This dissertation introduces a modeling framework, suitable for analysis, for systems that can be characterized either directly by the first and second laws of thermodynamics or indirectly by relating the fundamental equations characterizing a system or process to the first and second laws of thermodynamics. Models built in this framework coupled with a financial objective function produces a bilinear optimization problem. We compute the optimal solution by variable substitution into this bilinear problem, linearizing and relaxing the resulting bilinear constraint, and applying a branch and bound methodology. We illustrate the solution technique of the bilinear optimization problem applied to several energy systems. Using reported data characterizing several California power plants, we demonstrate how to determine an appropriate model utilizing the introduced modeling framework and fit the parameters required in the framework to the model. We consider problems with various sources of flexibility and uncertainty and apply our framework and methodology. Using standard programming techniques, we characterize common financial measures and strategies, such as optimal hedging and risk management and valuation of flexibility.