A wind turbine, comprising: a mechanical system; an electrical system; and a controller for, determining an electrical capability limit of the electrical system according at least in part to one or more operating conditions of the wind turbine and one or more environment conditions of a site of the wind turbine, comparing the electrical capability limit of the electrical system and a mechanical capability limit of the mechanical system, and controlling the electrical system to operate at the smaller one of the electrical capability limit and the mechanical capability limit; and wherein the controller comprises, a mechanical system controller for determining a first torque command according at least in part to a wind speed of wind; an electrical system optimizer for generating the electrical capability limit of the electrical system according to the first torque command, the one or more operating conditions and the one or more environment conditions to the mechanical system controller, the mechanical system controller determining a second torque command according to the first torque command and the electrical capability limit; and an electrical system controller for controlling the electrical system according to the second torque command; and wherein the electrical system optimizer is for, generating one or more state variables of the electrical system according at least in part to the first torque command and the one or more operating conditions of the wind turbine, determining a command margin according at least in part to the one or more state variables and the one or more environment conditions, and, adjusting the first torque command using the command margin in an iteration method until at least one of the one or more state variables substantially reaches to a corresponding state variable limit to obtain an optimized torque command. a mechanical system; an electrical system; and a controller for, determining an electrical capability limit of the electrical system according at least in part to one or more operating conditions of the wind turbine and one or more environment conditions of a site of the wind turbine, comparing the electrical capability limit of the electrical system and a mechanical capability limit of the mechanical system, and controlling the electrical system to operate at the smaller one of the electrical capability limit and the mechanical capability limit; determining an electrical capability limit of the electrical system according at least in part to one or more operating conditions of the wind turbine and one or more environment conditions of a site of the wind turbine, comparing the electrical capability limit of the electrical system and a mechanical capability limit of the mechanical system, and controlling the electrical system to operate at the smaller one of the electrical capability limit and the mechanical capability limit; and wherein the controller comprises, a mechanical system controller for determining a first torque command according at least in part to a wind speed of wind; an electrical system optimizer for generating the electrical capability limit of the electrical system according to the first torque command, the one or more operating conditions and the one or more environment conditions to the mechanical system controller, the mechanical system controller determining a second torque command according to the first torque command and the electrical capability limit; and an electrical system controller for controlling the electrical system according to the second torque command; and wherein the electrical system optimizer is for, generating one or more state variables of the electrical system according at least in part to the first torque command and the one or more operating conditions of the wind turbine, determining a command margin according at least in part to the one or more state variables and the one or more environment conditions, and, adjusting the first torque command using the command margin in an iteration method until at least one of the one or more state variables substantially reaches to a corresponding state variable limit to obtain an optimized torque command.