A building management system includes building equipment configured to consume electrical energy and generate thermal energy, thermal energy storage configured to store at least a portion of the thermal energy generated by the building equipment and to discharge the stored thermal energy, electrical energy storage configured to store electrical energy purchased from a utility and to discharge the stored electrical energy, and a controller. The controller is configured to determine, for each time step within a time horizon, an optimal amount of electrical energy stored or discharged by the electrical energy storage by optimizing a value function.