The ideia is which constraints you are dealing with. When you have a system with have Fixed Energy, Number of Particles and Volume (which we will end up calling micro-canonical ensamble), what you seek is to maximize entropy while respecting these constraints. So when you extremize entropy, you can't really extremize (internal) energy.
When a system can exchange energy but not Number of Particles nor volume, we speak of the Canonical Ensamble, where the Helmholtz Free Energy (or Helmholtz Potential) plays crucial role. Since you can exchange energy in form of heat with a bigger system (nicely called 'heat bath'), which is in termal equilibrium at temperature $T$, you can't really fix entropy because entropy can change when you exchange energy, nor it makes sense to extremize entropy because of this same heat flow. What you end up with is that you need a new 'variable' to extremize that you can maximize/minimize with constant number, volume and temperature. This guy is exactly the Helmholtz free energy.
You can go on with this reasoning, and depending on what you choose, you will end up with different thermodynamical potentials, like the Gibbs Free Energy or the Gran Canonical Potential.
All the way, we extremize each of these variables exactly because we believe they are maximum/minimum at thermodynamical equilibrium, while respecting the constraints that you impose in your system.