With the rapid growth in renewable energy and battery storage technologies, there exists significant opportunity to improve energy efficiency and reduce costs through optimization. However, optimization algorithms must take into account the underlying dynamics and uncertainties of the various interconnected subsystems in order to fully realize this potential. To this end, we formulate and solve an energy management optimization problem as a Markov Decision Process (MDP) consisting of battery storage dynamics, a stochastic demand model, a stochastic solar generation model, and an electricity pricing scheme. The stochastic model for predicting solar generation is constructed based on weather forecast data from the National Oceanic and Atmospheric Administration. A near-optimal policy design is proposed via stochastic dynamic programming. Simulation results are presented in the context of storage and solar-integrated residential and commercial building environments. Results indicate that the near-optimal policy significantly reduces the operating costs compared to several heuristic alternatives. The proposed framework facilitates the design and evaluation of energy management policies with configurable demand-supply-storage parameters in the presence of weather-induced uncertainties.