— In this paper, we propose a distributed stochastic algorithm for power and rate allocation in ad hoc wireless sensor networks. The problem we deal with is formulated as a transmission-plus-circuit energy optimization problem. We showed that the optimal solution can be obtained by solving two power and rate subproblems while either one parameter is fixed. Based on this result we developed two recursive algorithms for power and rate adaptation, respectively. It has been proved that these two recursive algorithms of updating power and rate will converge to a solution pair minimizing the total energy consumption of all the active sensor nodes in a mean square sense. The rate of convergence of these two algorithms is exponential so that the optimal power and rate values can be achieved in a few bit durations. The simulation results reveal that the energy consumption can be largely reduced if powers and rates are updated via the proposed algorithms.