To achieve an excellent dynamic balance during humanoid robot walks, it is essential to counteract the undesired yaw moment and deal with the nonlinearities existing in the system dynamics. In this paper, the problems of the dynamic balance optimization and yaw moment control for humanoid robot are investigated. First we formulate a constrained dynamic model of compliant joints for robots. Then, a yaw moment control approach based on quadratic objective function is proposed for computing optimal ankle torque to equilibrate the undesired yaw moment. In order to deal with the complicated optimization problem with inequality and equality constraints, a Quadratic Programming (QP) solver based on Linear Variational Inequality (LVI) is adopted. In comparison with the yaw moment control approaches studied previously, the main contributions of this paper are summarized as follows. 1) our newly proposed control scheme is more effective in counteracting the undesired yaw moment for the case of handling object-carrying tasks during walking. 2) a novel adaptive backlash inverse is included in the proposed scheme to cancel the unknown actuator backlash nonlinearity without a prior knowledge of the backlash nonlinearity. By the strict Lyapunov argument, the asymptotic convergence of the system tracking error to arbitrarily small neighborhood of the origin is proved. The simulation examples involving humanoid robot walking are constructed to validate the proposed algorithm.