This paper designs a microgrid energy controller capable of creating a charging or discharging schedule for electric vehicles (EVs), aiming at leveraging the integration of renewable energy and shaving the peak load in the microgrid. Dynamically activated on each time slotto cope with the prediction error for the power consumption and the renewable energy generation, the controller calculates the number of EVs to charge or make discharge first. Then, a greedy algorithm-based scheduler selects EVs according to the expected energy potentialduring their stays. The potential is the integral of a supply-demand margin function from thecurrent time to the expected departure time. A simulator is implemented for performance evaluation, comparing with uncoordinated scheduling, according to the number of EVs aswell as the behavior of energy load and production. The experiment result shows that theproposed scheme can reduce the energy waste by 16.9 %, cut down the microgrid-level energy insufficiency by 12.2 %, and enhance the amount of electricity supplied to EVs by 37.3%, respectively, for given parameter setting.