We propose a stochastic mixed integer optimization model to optimally size a solar power system and its battery storage for residential and nonresidential customers of electric power. The objective function of the model is to minimize the total cost associated with solar power system investments and the grid provided electric power over a planning horizon. We consider the uncertainty associated with solar radiation, load, and electricity price in the form of probabilistic scenarios. The model can be used with different grid pricing programs and under no net metering or net metering programs, respectively. A numerical example and its parametric analyses are used to demonstrate the efficacy of the model and develop some insights into optimal sizing of a battery storage enabled solar system. The analyses show the size of the solar system is influenced by the labor cost and the load size whereas the size of the battery storage is sensitive to the load size and the battery cost. Moreover, we find the optimal number of solar panels/batteries is larger under the net metering program than under no net metering program.