Optimal Energy Design of Wireless Ad Hoc Networks