This article studies the optimal control for networked control systems (NCSs) subject to Markovian packet dropouts and input delay. In this scenario, Markovian packet dropouts occur in two channels, that is, from sensor to controller and from controller to actuator. Meanwhile, the input delay arises in the channel from controller to actuator. The contributions of this paper are as the following two aspects: Firstly, based on Pontryagin's maximum principle, the solution to the forward and backward stochastic difference equations (FBSDEs) is obtained. Secondly, in virtue of the obtained solution to the FBSDEs, sufficient and necessary optimal control conditions are derived and the explicit expression of the optimal controller is presented. The validity of the results is illustrated by numerical examples.