The increase in the number of electric vehicles (EVs) has led to an increase in power demand from the public grid; hence, a photovoltaic based charging station for an electric vehicle (EV) can participate to solve some peak power problems. On the other hand, vehicle-to-grid technology is designed and applied to provide ancillary services to the grid during the peak periods, considering the duality of EV battery “load-source”. In this paper, a dynamic searching peak and valley algorithm, based on energy management, is proposed for an EV charging station to mitigate the impact on the public grid, while reducing the energy cost of the public grid. The proposed searching peak and valley algorithm can determine the optimal charging/discharging start time of EV in consideration of the initial state of charge, charging modes, arrival time, departure time, and the peak periods. Simulation results demonstrate the proposed searching peak and valley algorithm’s effectiveness, which can guarantee the balance of the public grid, whilst meanwhile satisfying the charging demand of EV users, and most importantly, reduce the public grid energy cost.