Realization of benefits from on-grid distributed generation based on renewable energy sources requires employment of energy storage to overcome the intermittency in power generation by such sources, while accounting for time-varying electricity prices. The objective of this study is to examine the effects of time-varying electricity prices on the performance of energy storage components for an on-grid hybrid renewable energy system (HRES) utilizing an optimized fuzzy logic controller (FLC). To achieve the objective, FLC membership functions are optimized for minimizing the operational cost of the HRES based on weekly and daily prediction of data for grid electricity price, electrical load, and environmental parameters, including wind speed, solar irradiation, and ambient temperature, using shuffled frog leap algorithm. FLC three inputs include (a) grid electricity price, (b) net power flow as the difference between energy produced and energy consumed, and (c) state of charge (SOC) of battery stack. It is confirmed that accounting for grid electricity price has considerable effects on the performance of energy storage components for operation of on-grid HRES, as the weekly and daily optimized FLCs result in less working hours for fuel cell and electrolyzer and less fluctuations in SOC of battery stack.