Two different techniques for the integration of renewable energy in smart grid systems are considered. The first is storage, which smooths the fluctuations of the renewable energy generation across time. The second is the concept of distributed generation combined with cooperation by exchanging energy among the distributed sources. This technique leads to energy aggregation from diverse sources, which averages out the variation in the energy production across space. The trade-off present between the two techniques is analyzed, and the optimal combination of storage and cooperation to achieve a certain grid performance is investigated. The problem is formulated as a stochastic optimization problem with the objective of minimizing the time average cost of energy exchange within the grid. First, an analytical model of the optimal cost is provided by investigating the steady state of the system for some specific scenarios. Then, an algorithm to solve the cost minimization problem using the technique of Lyapunov optimization is developed. The algorithm is implemented on the renewable energy data provided by National Renewable Energy Laboratory (NREL) of the United States. The results show that in the presence of limited storage devices, the grid can benefit greatly from cooperation, whereas in the presence of large storage, cooperation does not yield much benefit.