In this study, a framework is developed to perform two-stage stochastic programming in a district energy system. This framework optimizes the sizing of energy components to minimize the total cost and operating $CO_2$ emissions. Uncertainties in electricity demand, solar irradiance, wind speed, and electricity emissions are considered. A group of buildings at University of Utah is used as the case study to test the optimization framework. This study is novel by forming an open-source framework, considering electricity emissions with more details compared to previous studies in the literature, and performing the optimization for a campus in the U.S. This study’s results show the trade-off between cost and emissions when different energy configurations are used for three electricity purchasing cases. This framework can help facility managers to evaluate the optimum sizing of their district energy system to minimize the cost and emissions.