Why is that a system lowering its Helmholtz/Gibbs free energy must automatically have the same temperature as its environment? Let's say we have a system in contact with a large reservoir.  Let's also fix the number of particles in the system, as well its volume, so that the only thing that could be exchanged is energy.  Now we know that any increase in entropy must be the sum of any increase in entropy in the system plus any increase in entropy in the reservoir:
$$dS_{total} = dS + dS_R.$$
Generally speaking, any change in entropy is due to the following factors:
$$dS = \frac{1}{T}dU + \frac{P}{T}dV + \frac{\mu}{T}dN.$$
But as we said above, we are fixing the volume and the number of particles, so in our case:
$$dS = \frac{1}{T}dU.$$
This is also true of the reservoir:
$$dS_R = \frac{1}{T_R}dU_R.$$
Putting this into our equation for the total entropy:
$$dS_{total} = dS + \frac{1}{T_R}dU_R.$$
We also know that any change in the energy of the system is a loss for the reservoir:
$$dU = -dU_R.$$
Up to here, I have no issues.  However, the textbook I am looking at now makes the following assertion:
"...the temperature of the reservoir is the same as the temperature of the system,"
which means that $T_R = T$.
Substituting $T_R$ for $T$ and $U_R$ with $-U_R$:
$$dS_{total} = dS - \frac{1}{T}dU = -\frac{1}{T}(dU - TdS) = -\frac{1}{T}dF,$$
where F is the Helmholtz free energy, $U-TS$.  In the other words, increasing total entropy involves lowering the system's Helmholtz free energy.
Using a similar argument, where the pressure, rather than the volume, is kept constant, it can be shown that $dS_{total} = -\frac{1}{T}dG$, where G is the Gibbs free energy, $U+PV-TS$.
Here's my dilemma: why do you assume that the temperature of the system is equal to that of the reservoir?  Generally speaking, a system and its environment's temperatures wouldn't necessarily be the same.  
Okay, so maybe the intent of all this is to imply that the equation only holds once the system has reached the same temperature as the reservoir.  But if this were the case, would that really make sense?  After all, since the system and the reservoir are the same temperature, there will be no net heat flow between the two.  And in the first case, since the volume is fixed, there is no expansion of either the system or the reservoir.  By the first law of thermodynamics, $U=W+Q$.  We've already said that Q would have to be 0 and W cannot be an work that comes from a changing volume.  This only leaves "other" work ("such as electrical work", whatever that even means).  Then the equation would just say:
$$dS_{total} = dS + dS_R = \frac{1}{T}dU + \frac{1}{T}dU_R.$$
Since I don't really get what $W_{other}$ is, I can't say for sure that $dU_R = -dU$, but let's say it is so and that the reservoir is doing the "other" work on the system.  Otherwise the assumption that $dU_R = -dU$ is wrong, which is specifically against the textbook's assumptions. So if we make this assumption then we get:
$$dS_{total} = \frac{1}{T}dU - \frac{1}{T}dU = 0.$$
So it's trivial: If they are the same temperature there is no heat flow, plus there is no expansion work done by constraint, and any "other" work done must increase one's entropy by the exact decrease in the other, since they are both at the same temperature.
So either $T_R=T$ and the answer is trivial, or $T_R\neq T$ which is not what the textbook said, making the textbook's whole derivation wrong.
Yet the textbook has to be correct so I must be wrong, but how?
 A: The exposition in Thermal Physics by Schroeder, section 5.2, is somewhat botched, but the idea is sound. What is actually assumed in these kinds of argument is that the system has the same temperature as the reservoir just before the process, and just after the process. Temperature of the system during the process is immaterial. It may not even be defined.
If temperature of the system was the same all the time, one would be tempted to additionally assume that the whole process is reversible and use the relation
$$
dS = \frac{dQ}{T}.
$$
Then $S_{total}$ would be constant during this process. But this is not what is being studied.
What is being studied is any irreversible process, which starts and ends at the same temperature as that of reservoir $T_R$. Thus a better way to write down the result would be
$$
\Delta S_{total} = -\frac{1}{T_R}\Delta(U-TS)
$$
with deltas instead of differentials, to stress the fact that values at endpoints of a possibly long-running process are considered.
I wrote $U-TS$ instead of $F$, because for some systems, $F$ is more complicated than just $U-TS$, such as for mix of liquid water and ice, see e.g. this answer by GiorgioP:
Entropy as a function of temperature: is temperature well defined?
