Recently, the use of renewable energy sources (RES) and electric vehicles (EVs) has been rapidly increased worldwide. As a result of the highly fluctuating nature of RES, the charging and discharging rates of EVs significantly have to be increased, and so the lifespan of EV batteries decreases. In this paper, an optimization-based method is proposed to smooth voltage fluctuations due to various RES types by optimally controlling the charging and discharging power of EVs and the reactive power of the RES inverters. To extend the lifespan of the EV battery, EV power fluctuations and their minimum preset state of charge (SOC) are considered in the proposed optimization model. For this purpose, a new multi-objective function is formulated, including 1) voltage fluctuations, 2) EV power fluctuations, and 3) the deviation of SOC of EVs from their minimum desired level. The use of the hull moving average (HMA) is proposed to mitigate voltage fluctuations, which eliminates the lag problem of the widely used moving average methods. The gravitational search algorithm (GSA) is utilized to accurately solve the optimization model. The simulation results demonstrate the effectiveness of the proposed method to smooth voltage fluctuations while considering degradation and charging plan of EV batteries.