Microgrids play an essential role in the integration of multiple distributed energy resources in buildings. They can meet critical loads in buildings while reducing peak loads and congestion and providing other types of ancillary services to the main electrical grid. Sizing the components of microgrids and scheduling their optimal operation while jointly integrating uncertain renewable energy generation and loads can significantly affect its ability to meet these objectives. In fact, microgrids face great challenges due to renewable energies and load uncertainties. In this paper, a two-stage stochastic programming model for optimal sizing and operation of various distributed energy resources for peak load shaving in district buildings is proposed. The first stage is related to the planning of photovoltaic panels and batteries, while the second stage aims to find the optimal operation of the system in grid-connected mode. The uncertainties are related to photovoltaic power generation and loads. The Generative Adversarial Network (GAN) is implemented to generate the scenarios of uncertain parameters, and the k-medoids classical method for scenario reduction is applied to decrease the number of scenarios. The proposed two-stage stochastic optimization is tested for a real case study of a university campus in Canada.