In this article, the optimal linear quadratic control problem is considered for the wireless sensor and actuator network with stochastic network-induced delays and packet dropouts. Considering the event-driven relay nodes, the optimal solution is obtained, which is a function of the current plant state and all past control signals. It is shown that the optimal control law is the same for all locations of the controller placement. Since the perfect plant state information is available at the sensor, the optimal controller should be collocated with the sensor. In addition, some issues such as the plant state noise and suboptimal solution are also discussed. The performance of the proposed scheme is investigated by an application of the load frequency control system in power grid.