In the first part we derive for transformations of stationary states of diffusive systems an expansion of the energy balance around the quasi static limit. We then characterize the transformations which minimize the energy dissipation by discussing the optimal correction to the quasi-static limit. Contrary to intuition, in the case of transformations between homogeneous equilibrium states of an ideal gas, the optimal transformation is a sequence of inhomogeneous equilibrium states. In the second part we analyze an exact formula which connects the change of equilibrium free energy (or entropy) in a quasi-static transformation to the corrections of hydrodynamics near this limit. We finally consider the applicability in our context of Clausius notion of equivalent transformations.