In this paper we study how to maximize the lifetime of randomly deployed wireless sensor networks by applying adaptive traffic distribution and power control. We model this problem as a linear program by abstracting the network into multiple layers. First we focus on the scenario where transmission energy consumption plays the dominant role in overall energy consumption. After ignoring the processing energy consumption, we observe that: in order to maximally extend the lifetime, each node should split its traffic into two portions, and send one portion directly to the sink, and the other one to its neighbor in the next inner layer. Next we consider the effect of incorporating the processing energy consumption. In this case, we have similar observation: for each packet to be sent, the sender should either transmit it using the transmission range with the highest energy efficiency per bit per meter, or transmit it directly to the sink. Besides studying the upper bound of maximum achievable lifetime extension, we discuss some practical issues, such as how to handle the signal interference caused by adaptive power control. Finally, we propose a fully distributed algorithm to adaptively split traffic and adjust transmission power for randomly deployed wireless sensor networks. We also provide extensive simulation results which demonstrat that the network lifetime can be dramatically extended by applying the proposed approach in various scenarios