The improved particle swarm optimization algorithm is employed to optimize the distributed generations of independent microgrid. With considering the day-night characteristics of PV, load and its impact on reliability of power supply, the objective function which contains initial investment cost of equipments, maintenance cost, replacement cost of batteries, fuel cost and punishment cost of the environmental pollution is built. The day-night reliability of power supply is improved while the total cost is reduced. The influence of battery sizing and power supply capacity of WT and PV on optimization results are studied after analyzing the day-night output characteristics of batteries and diesel generators. The final results of example show that the models in this article are reasonable.