The first law for a closed system

For a closed system the heat in less the work out is the rise in its stored energy, $Q - W = \Delta U + \Delta KE + \Delta PE$, and over a cycle the net heat in equals the net work out.

From Thermodynamics.