A framework for the joint design of wireless network and controllers is proposed. Multiple control systems are considered where the sensor measurements are transmitted to the controller over the IEEE 802.15.4 protocol. The essential issues of wireless networked control systems (NCSs) are investigated to provide an abstraction of the wireless network for a co-design approach. We first present an analytical model of the packet loss probability and delay of a IEEE 802.15.4 network. Through optimal control techniques we derive the control cost as a function of the packet loss probability and delay. Simulation results show the feasible control performance. It is shown that the optimal traffic load is similar when the communication throughput or control cost are optimized. The co-design approach is based on a constrained optimization problem, for which the objective function is the energy consumption of the network and the constraints are the packet loss probability and delay, which are derived from the desired control cost. The co-design is illustrated through a numerical example.