In recent years, multihop wireless networks have been playing a key role in many Internet of Things applications. Due to the limited resources of wireless nodes, extending the network lifetime is one of the most crucial issues, which needs to be concerned. This paper aims to maximize the network lifetime by appropriately distributing the tasks of the applications for each node in the network. First, a centralized optimal task allocation algorithm for multihop wireless networks (COTAM) is proposed by modeling the problem of maximizing the network lifetime as a linear programming (LP) problem. As the centralized algorithm requires knowing all the network parameters in advance, COTAM is mostly restricted to the off-line optimization in known environments. To extend the usability of the approach, this paper further proposes a distributed optimal task allocation algorithm (DOTAM) based on Dantzig-Wolf decomposition. DOTAM divides the centralized large-sized LP problem into small-sized subproblems, which are independently executed by each node. The proposed COTAM and DOTAM are tested by applying both the artificially generated applications and a realistic application. The extensive results demonstrate that DOTAM achieves the same performance as COTAM. Comparing with existing methods, they provide significant improvements on extending the network lifetime.