This work develops a dual-layer energy management (DLEM) model for a microgrid (MG) consisting of a community, distributed energy resources (DERs), and a grid. It ensures the participation of all these energy entities of MG in the market and their interaction with each other. The first layer performs the scheduling operation of the community with the goal of minimizing its net-billing cost and sends the obtained schedule to the DER operator and grid. Further, the second layer formulates a power scheduling algorithm (PSA) to minimize the net-operating cost of DERs and takes into account the load demand requested by the community operator (COR). This PSA aims to achieve optimal operation of MG by considering solar PV power, requested demand, per unit grid energy prices, and state of charge of the battery energy storage system of the DER layer. Moreover, to study the impact of electric vehicles (EVs) load programs on DLEM, the advanced probabilistic EV load profile model is developed considering practical and uncertain events. The EV load is modelled for grid to vehicle mode, and a new mode of EV operation is introduced, i.e., vehicle to grid with EV demand response strategy (V2G_DRS) mode. The solar PV and load demand data are obtained from the MG setup installed and buildings present at the university campus. However, a scenario reduction technique is used to deal with the uncertainties of the obtained data. In order to evaluate the efficacy of the developed DLEM, its results are compared to previously reported energy management models. The results reveal that DLEM is superior to the existing models as it decreases the net-billing cost of COR by 13% and increases the profit of the DER operator by 17%. Further, it is found that for the highest EV penetration, i.e., 30 EVs, the V2G_DRS mode of EV operation reduces the total energy imported by COR by 11.39% and the net-billing cost of COR by 7.88%. Therefore, it can be concluded that the proposed model with the introduced V2G_DRS mode of EV makes the operation of all the entities of MG more economical and sustainable.