Electricity distribution networks are rapidly becoming more complex. Distributed generation (DG) is increasing and some DG units are intermittent renewables such as solar or wind. Moreover, plug-in electric vehicles (EVs) are expected to be deployed in large numbers over the next decade. These changes present opportunities as well as challenges for reliable and efficient operation of distribution networks. In this paper, we present a new stochastic model in which market clearing prices are endogenously determined. Potential suppliers include the main grid supply, a range of different DG technologies within the distribution network, and EVs operated in vehicle-to-grid (V2G) mode. We allow for supply uncertainties for renewable resources and also allow for uncertainties in EV availability for charging and discharging. Using stochastic optimal power flow (SOPF) based on monte-carlo simulation, we analyze the effects of operating distributed energy resources (DERs) on social welfare considering emission taxes.