The reason for the different kinds of energy is because there are different kinds of constraints affecting a system.
Suppose you have a small system that is free to exchange energy with a much larger system (say, a reservoir of gas or liquid). In that case, it doesn't make sense to say that the small system should minimize its energy, because any energy that leaves the small system must go to the large system. What it does make sense to do is to maximize the total entropy, [itex]S[/itex], which is the sum of the entropy [itex]S_1[/itex] of the small system and the entropy [itex]S_2[/itex] of the big system.
Maximizing the total entropy turns out to be the same thing as minimizing the quantity
[itex]\mathcal{E} - S_1(\mathcal{E}) T[/itex]
where [itex]\mathcal{E}[/itex] is the energy of the small system, subject to the constraint that [itex]T =[/itex] constant.
If the volume of the small system is allowed to change, as well, (imagine a balloon in a much larger room--the balloon can increase its volume, but only by decreasing the volume available in the room outside of the balloon), then maximizing the total entropy in this case is the same thing as minimizing the quantity
[itex]\mathcal{E} - S_1(\mathcal{E}) T + P V_1[/itex]
where [itex]V_1[/itex] is the volume of the small system, subject to the constraints that [itex]T =[/itex] constant and [itex]P =[/itex] constant.
The appropriate values for [itex]P[/itex] and [itex]T[/itex] are determined by the entropy of the large system:
[itex]\frac{1}{T} = \frac{\partial S_2}{\partial E_2}[/itex]
[itex]\frac{P}{T} = \frac{\partial S_2}{\partial V_2}[/itex]
where [itex]E_2[/itex] is the energy of the large system and [itex]V_2[/itex] is its volume.