Energy is one of the most important and abstract concepts in physics. In nature, one can see its manifestation, in various forms and it can only be measured indirectly. Mechanical energy is all-encompassing and concerned with every system in nature. Conservation of this energy is the principle which can be used to predict the behavior of any system in nature, if we know the initial conditions.
Mechanical energy is the sum total of the potential and kinetic energies, associated with any system. Potential energy is the dormant energy stored inside any physical system due to the nature of its configuration and the presence of a force. It depends on the position of various parts in a system and intrinsic properties of matter like charge and mass.
On the other hand, kinetic energy is the energy possessed by any physical object or system due to its motion. It is the activated form of potential energy of a system.
The sum total of potential and kinetic energies of a system, is the net mechanical energy of the system. It is incorrect to say that this energy is something just connected with machines. It is the totality of all forms of energy associated with a system. The system may be anything, ranging from a ball tossed in air, to a molecule of water, or just an atomic nucleus. It is measured in the SI unit of 'Joule'.
The definition itself should make the formula quite clear to you.
Mechanical Energy of a System = Total Potential Energy Stored in System (V) + Kinetic Energy of the System (T)
The specific expressions for potential and kinetic energies of a system are dependent on its peculiar configuration and the forces at work in a system. In advanced physics or classical mechanics, the sum of the kinetic and potential energies, is known as the 'Hamiltonian'.
It is a known fact of nature that every interaction occurs in such a way that the sum total of mechanical energy, before and after interaction, remains the same in an isolated system. The principle can be stated as follows:
V1 + T1 = V2 + T2
where V1 is the potential energy before interaction, T1 is kinetic energy before interaction, V2 is potential energy after interaction and T2 is kinetic energy after interaction. As an example, consider a gun, before and after firing of the bullet. The mechanical energy of the bullet and gun, before and after firing, should be the same. This principle of conservation of energy causes the gun to recoil after firing. To figure out why, set up the conservation equation for the bullet and the gun, before and after firing.
Using the principle of energy conservation, you can solve many complicate problems in physics. All you have to do is keep an account of the energy balance, before and after any interaction and equate it to get answers. These conservation principles are built into nature and everything operates according to them. As you go deeper in the study of physics, you will be able to appreciate the inherent beauty of physical laws.