Average Structural and Marginal Costs as Result of a Unified Formulation of the Thermoeconomic Problem