## 1 Introduction
The proposed scheme in [16] assigned preference time zones with different energy tariffs to customers in order to charge their vehicles. Authors in [18] simulated an EV charging model for an individual EV load profile under a real-time price (RTP) to minimize electricity payments for users. In addition, [PERSON] et al. [19; 20] studied the online peak-minimizing algorithm for an aggregator, which managed a large set of EV charging jobs with deadlines by planning the charging schedules in order. With respect to the distribution power system, [PERSON] et al. [21] presented a new approach for the coordination of the charging and discharging of multiple EVs in a smart distribution system. The main objective was to minimize the peak shaving and active power losses. [PERSON] et al. [22] developed and implemented an optimization algorithm for managing EV charging by considering a genetic algorithm in a low voltage distribution system. The proposed algorithm took into account the thermal line limit, transformer loading, parking availability, and voltage limits. [PERSON] et al. [23] proposed a hybrid optimization algorithm for minimizing EV charging costs using energy storage management in a PV-integrated charging station. The algorithm considered the real-time electricity price and real-time PV output from the solar system in the PV-integrated charging station. In order to maintain the technical limits of the power grid, power grid operators are aiming to design flexible EV charging schemes while satisfying the vehicle owner's preferences. To achieve this goal, bidirectional power and information flows are required. Therefore, the aggregator plays the main role between the power grid operator and vehicle owners in the EV system. For encouraging end users to change energy usage habits, time-of-use (TOU), real-time pricing (RTP) and critical peak pricing (CPP) are different price-based options as defined by the US Dept. of Energy during different time-periods [24; 25]. The activities of EVs including charging and discharging enable them to participate in various domains such as vehicle-to-home (V2H), vehicle-to-building (V2B), V2G and vehicle-to-vehicle (V2V) [26; 27; 28]. V2B consists of EVs, bidirectional chargers and small-scale renewable energy resources, such as photovoltaic systems and small-scale wind turbines. EVs are able to draw/transfer the energy from/to the building based on their battery status and offer services such as reducing the on-peak load of the building's power consumption through peak shaving, load shifting and valley filling. This paper studies the impact of EV charging on the building's power consumption and presents a cost-effective solution for peak load minimization in an educational building equipped with a PV system and an ESS. In this work, we propose an optimal energy management algorithm (OEMA) for peak load minimization in a university campus. The system model consists of an educational building with laboratories, a smart parking lot, EVs, PV panels and an ESS. We also propose a time allocation scheme for EV charging and discharging based on priority. The priority determination rules are calculated based on different decision factors including both vehicle and user preference. We define three different priority levels as high, medium and low. Charging services will be allocated to EVs with higher priorities without violating the operational constraints of the grid. The proposed scheme is designed to minimize EV charging cost while balancing the load of the power grid. The simulation results outperformed the conventional charging method in terms of peak power and charging cost. The remainder of this paper is organized as follows: Section 2 presents the system architecture and components. Section 3 explains the proposed optimal energy management algorithm in detail. Section 4 presents the simulation results and a discussion of different scenarios and the conclusion is given in Section 5.