**1. Introduction**

Buildings have become the major energy consumers over the world as they consume around 40% of total end-use energy [1]. In Europe, the Directive on Energy Performance of Buildings establishes a "nearly Net Zero Energy buildings" (NZEBs) as the aim for all new buildings from 2020 [2]. In recent literature, more and more studies consider nZEBs as part of a smart grid or a micro-grid (MG) and identify trends on energy management techniques and technological solutions for electric power system management. The main advantages of nZEBs have been identified to be the integration of renewable energy sources; the integration of energy storage mechanisms such as plug-in electric vehicles and the

implementation of zero-energy concepts such as net zero source energy, net zero energy costs and net zero emissions.

The renewable energy exploitation is one of the most important aspects of NZEBs. Renewable Energy Sources (RES) are those sources of energy that can be derived from natural processes and thus can be replenished continuously such as solar energy, wind energy, biomass, hydropower etc. The wind and solar energies are mostly used in green buildings modeling and design [3] but they come with a number of issues that have to be taken into consideration. The wind energy systems may not be technically feasible at all sites due to the low wind speeds and/or to high unpredictability with respect to solar energy. In addition, the availability of a specific resource depends each time on the corresponding season and may also vary during the day [4]. NZEBs, either as standalone or as parts of a Net Zero Energy District, could help improving the energy performance of an electrical grid by shifting loads and reducing peak demands. Buildings, as one of the most important contributors involved in a smart grid, can deliver useful information such as energy behaviors, power demand and the corresponding load shifting potentials for grid control and optimization [5].

A microgrid is an electric system of limited extent, typically the suburban/ district level, that includes distributed generation (i.e., solar, wind, cogeneration, electric vehicles, etc.), consumers and storage facilities, and operates by intelligently managing its own costs and production capacity to ensure a level of quality service. It is connected to the global grid but is designed to operate independently if necessary (islanded mode). Microgrid can be understood as a case of a more general concept called 'Smart grid', collecting a set of technological solutions for electric power system management. Its localized nature allows responding efficiently and accurately the energy needs and ensuring adequate levels of quality, safety, security, reliability, and availability. It is able of being disconnected from the global network for several hours without loss of service while ensuring voltage and frequency stability. In addition, the proximity of the sources of production to the consumption allows reducing energy transmission losses. Thus, the use of such a system (mainly decentralized) has as an aim to gain flexibility and adaptability with respect to the classical centralized power system model.

The development and the extensive utilization of building automation systems, Information and Communication Technologies (ICT) and grid energy management system facilitates the bidirectional communication between buildings and a grid which can be widely established and therefore be used for interacting and optimizing the power supply and the demand. This chapter attempts to address the major issues that are related to the design and optimization of grid-connected nearly and/ or net zero energy buildings as parts of a smart grid and on which several scholars/ researchers have been working the last years.

In this work, a microgrid with a certain number of DER components connected to an office building (in a university campus) provided with electricity by a utility company is considered. These components include a 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. PV production and electric load are modeled under uncertainty. We use actual data from smart meters to formulate the scenarios. We also assume that each DER element can, through an EMS controller, to communicate and control the power exchange from and towards this component. We also consider that two-way communication with the utility company can be achieved via aggregators using advanced metering infrastructure. The energy generated by the DERs can be sold to the grid by the microgrid building-manager, and/or it can be stored for future utilization. The recommended EMS configuration is shown in **Figure 1**.
