**Abstract**

In this Chapter, we consider a microgrid with a certain number of distributed energy resources (DER) components connected to an office building (in a university campus) provided with electricity by a utility company. We develop the initial version of the energy management system which is responsible for the optimal energy scheduling of the microgrid's distributed energy resources. These resources include a photovoltaic (PV) installation, a Storage Energy System (ESS), a small Combined Heat and Power (CHP) unit, and a fleet of electric vehicles (EVs) used for work-related trips. The mobility behavior of the EVs fleet is modeled considering deterministic realizations of the probabilistic distributions used for the arrival/ departure, and the time EVs remain parked. To investigate the impact of renewable generation and load unpredictability on the energy management system (EMS) operation, PV production and electric load are modeled under uncertainty using actual smart meters data for the scenarios formulation. We also assume that each DER component, through an EMS, can communicate and control the power exchange from and towards this component and that, two way communication with the utility company can be reached through aggregators using advanced metering equipment. We also consider a simplified thermal model that provides a specific level of thermal comfort to the building's occupants, by meeting the predicted heating load. The energy produced by the DERs can be sold back to the grid by the microgrid manager and/or it can be stored for future utilization.

**Keywords:** energy management system, smart grid, electric vehicles, distributed energy resources, optimization
