Concerning the complete transition to clean energies, considerable progress has been achieved by increasing the share of renewable energy sources (RES) in the global electricity matrix, highlighting wind and solar power 
due to their cleanness and, in the case of solar power, easy integration into buildings through building-integrated photovoltaic (BIPV) technology 
. Among the multiple challenges regarding this topic, two of them present a higher difficulty level, namely, the uncertainty of local energy generation and electric vehicles (EVs) charging demand and the development of an optimal energy management system (EMS) that can simultaneously consider multiple components. As examples of advancements developed to address these challenges, Ref. 
proposed an EV-based decentralized charging (EBDC) algorithm based on model predictive control (MPC) to optimally coordinate the charging of EVs in buildings integrating wind turbines dealing with the uncertainty of local generation and charging demand. The balance of the system was improved, and the combination of this method with event-based optimization was suggested as future work.
used BIPV technology to assess the economic potential of charging an e-car-sharing fleet of a residential building considering multiple agents in Austria with mixed integer linear programming (MILP) as the chosen optimization strategy. Through the analysis of various scenarios, the results showed that the proposed model reduces energy costs by up to 29% depending on the scenario. Furthermore, Ref. 
also applied BIPV to address both challenges simultaneously at an office building through the development of two new algorithms, namely, stochastic programming and load forecasting, for energy management with two stages (SPLET) and sample average approximation-based SPLET (SAA-SPLET) with the participation of both day-ahead planning and real-time operation. The combined use of these algorithms generated an average reduction in costs of 7.2% for SPELT and 6.9% for SAA-SPET.
2. Vehicle-to-Grid Technology
Decarbonizing the transportation sector plays a vital role in mitigating the effects of climate change 
, and internal combustion engine vehicles (ICEV) are being gradually replaced by technologies with lower emissions, such as natural gas, liquefied petroleum gas (LPG) 
, and even biofuels, as is the case of ethanol and biodiesel 
. However, the contribution of these technologies to reducing GHG emissions is small, and only electrification, taking advantage of the increasing share of RES in the electrical grid, can have a major impact. The powertrain options that comprise this shift are PHEV (plug-in hybrid electric vehicles) and BEV (battery electric vehicles) 
, since HEV (hybrid electric vehicles) and FCV (fuel cell vehicles) are not charged using the electrical grid.
Beyond contributing to lower emissions and a better quality of life in urban environments, EVs can be used as a flexible resource regarding (dis)charging management or even as a storage system 
when integrated with the electrical grid, ensuring better resilience and safety for the entire system or at a microgrid (MG) level 
. This technology is referred to as vehicle-to-grid (V2G) technology, and it will play a vital role in the context of smart cities. The main differential of V2G technology is the capacity of the EV to reinject electricity into the grid, which can greatly contribute to improving the match between local renewable generation and energy demand, and, consequently, can reduce energy costs. As disadvantages, V2G leads to additional cycles that will accelerate the degradation of the battery and requires the use of bi-directional chargers to allow the vehicle to trade energy with the grid, which is still too expensive to be implemented on a commercial scale, as well as the use of equipment capable of managing the energy flow between the entities. Ref. 
compared the use of V2G and other charging strategies for an office building in Austria. Additionally, other benefits achieved when using V2G include grid load stabilization, improvements in renewable energy consumption, improvements in users’ economic efficiency, and energy loss reduction 
. Ref. 
presented a review of V2G in terms of the advances already achieved and the challenges for the future. As an example of the previously mentioned capabilities, Ref. 
discusses how EVs can be a flexible load resource for a car-sharing fleet. Additionally, the impacts at the economic and energy levels, as well as the challenges and prospects of the increased presence of EVs and their technological development, have been widely studied in recent years 
studied the impact of the shift from ICEV to EVs on the electrical grid for a business campus in Portugal and discussed the current level of maturity and the future prospects of electric mobility at a national level. Another important level to consider is user behavior, where primary focus is given to the reasons that lead to EV adoption and how users typically use or want to use the EV and, consequently, the charging infrastructure. These factors together comprise the stochastic parameters of EV drivers and have an important role in the development of new methods for efficient energy management. In 
, a comparison between conventional vehicle users and BEV users was performed in Denmark and Sweden applying the “theory of planned behavior”. The development of smart strategies such as one-slot look ahead (OSLA) 
and the self-adaptive modified clonal selection algorithm (SAMCSA) 
for the energy management and decentralization of energy generation through the interaction of EVs with parking lots and houses, and with increasing attention, public buildings (PBs) 
, will contribute to a stable, smart, and efficient electricity network and enhance the potential of vehicles as paramount tools of decarbonization.
The first interactions of EVs with the grid start in small environments such as charging stations (CSs), where PHEVs are connected to a charging station integrated with the main power grid and a local PV generation site 
. The objective of the previously cited study was to charge the PHEVs with the maximum PV energy possible and alleviate the stress on the grid. The proposed control system was based on DC link voltage changes, which vary as a function of solar irradiation. With the proposed intelligent charging system, such operations did not impact the grid during peak hours. A different approach was proposed by 
through the integration of 200 EVs with a smart parking lot and its EMS with the objective of reducing RES intermittence, improving the security of charging operations, and generating financial benefits for both the parking lot and the EV owners. In addition to successfully achieving the established goals, it was the first time that the energy reserve capability of these vehicles was demonstrated. On a larger scale, EMS was also applied by 
, where an integration system for PHEVs and a building was developed, focusing on maximum comfort for the users with minimal energy consumption. To address this challenge, particle swarm optimization (PSO) was used, and the comfort levels were maintained.
developed the first CS with solar/wind generation integrated with the main power grid and V2G technology aiming to charge PHEVs and increase the matching between generation and demand. In 
, the CS system was further developed, with the inclusion of a fuel cell and electrolyzer system that generated electricity and hydrogen, respectively, to store the generation surplus using hydrogen. In addition, the system was a stand-alone system, meaning it was a completely independent operation from the main power grid.
3. Interactions between EVs and Buildings
The integration between EVs and buildings (residential and large PBs) occurs when the vehicle is connected to the building, regardless of the electricity generated in the building or provided by the grid. To increase the provided flexibility, a charger with bi-directional capabilities should be installed, meaning that the vehicles can be charged normally and can also work as a support system for local energy generation and decentralization of electricity generation. With this in mind, the need for smarter charging methods arises. Ref. 
developed a smart method to charge EVs at home or in buildings using PV panels. Additionally, batteries can be integrated into the system, as seen in 
, where the authors integrated batteries with EVs in an MG using an artificial neural network (ANN) and a reverse Monte Carlo (RMC) method to optimally determine the most cost-effective configuration for PV–EV charging stations. The proposed framework had a 95% optimality rate, and the authors intended to consider EV bi-directional flow as their future work. The main advantage of such interactions can be an increased match between energy generation and demand using demand–response strategies 
, therefore minimizing the electricity imported from the grid. Additionally, a path to allow buildings to purchase energy from the EV owners and vice versa can be opened, enabling the creation of entire communities that generate and share their own electricity with each other, which are called energy communities.
In Figure 1
, four different scenarios for a new building-to-vehicle-to-building (𝑉2𝐵2
) concept are presented. In this novel system developed by 
, houses and office buildings interact with each other and the grid at the MG level with the participation of PVs, EVs, and storage systems, evaluating the potential of the vehicles as energy vectors in the system. In all cases, the grid is always connected either to the house or the office building. For the first scenario, the conventional energy flow is represented, where both buildings receive energy from the grid in the traditional way, and the energy flow between the EV and the house is unidirectional, that is, it only flows to charge the vehicle. In Scenario 2, the house is equipped with PV panels and a battery (called a house stationary battery (HSB)), and the EV battery (EVB) can be charged either by the grid or by the HSB when a PV surplus is available. The novelty is that the EVB can transfer the potential electricity generated by the HSB to the office building, where the installed chargers can recharge the vehicle, if necessary. The operational logic of Scenario 3 is identical to Scenario 2, with the difference being that the house has a battery identical to the EVB. In this case, the batteries can be swapped, avoiding energy transfer from the HSB to the EVB (when recharging is demanded). Moreover, the EV can be recharged at the office (only for commuting purposes) and at home. Finally, in Scenario 4, the operational logic is identical to Scenario 3, but with the panels now installed at the building, and the house can be fed by the EVB (and also charge the vehicle for moving purposes, if necessary). Additionally, there are no stationary batteries at the office building, and the PV generation surplus is sold to the grid. Further, the authors used the computer simulation code DETECt 2.3 as the method to assess the energy demand of the building. The results show that financial savings were achieved (between 45% and 77% depending on the scenario), and the most important finding is that EVs are capable of working as an energy-transferring resource between houses and office buildings.
Figure 1. Different scenarios of the V2B2 concept.
Although important advances have already been achieved, there are still challenges that must be addressed, and together, optimization strategies must be found to increase the efficiency, reliability, and smartness of such novel systems. An MG management study involving EVs was performed by 
, where the authors developed a control strategy to reduce power factor issues caused by the inclusion of EVs and distributed generation (DG) resources for the referred MG. To achieve the objectives, dynamic programming was used. Through the results, it was noticed that the power factor remained above the reference value of 0.95 and that future work should consider voltage and frequency regulation. Some challenges to enhance the referred integration are pointed out by Refs. 
, such as incorporating the stochastic parameters of the vehicles and the occupants of the buildings, uncertainty in RES production, capacity expansion, etc.