The optimal operation strategy of active distribution networks is investigated by this paper. The energy storage system (ESS) and distributed generation (DG) are utilized in the proposed planning. The paper presents two-level planning including short term and long term planning. The long term planning installs ESSs and diesel DGs on the network and the short term one determines an hourly optimal operation strategy for ESSs and diesel DGs. Different types of DG including solar photovoltaic (PV), wind, and diesel are studied at the same time. The objective function of the planning is to minimize annual operation cost of distribution network subject to security constraints of the network. The uncertainty of solar-wind units is estimated by many scenarios and stochastic programming is carried out to solve the problem. The proposed problem is expressed as a nonlinear mixed integer programming and solved by modified PSO algorithm. In order to cope with the real conditions, reactive power of ESSs and diesel DGs are included in the problem. Depth of discharge is also considered as a design variable and optimized for ESSs. The planning optimizes a large number of design variables at the same time including size and location of ESSs and diesel DGs, daily operation of diesel DGs, daily charging-discharging pattern of ESSs, and optimal depth of discharge for ESSs. The results demonstrate that the proposed two-level planning can effectively reduce cost and losses as well as increase efficiency and performance of the network.