This paper develops an optimal control (OC) model of a heat pump water heater (HPWH) supplied by a wind generator–photovoltaic-grid system. The objective function is energy cost minimization, taking into account the time-of-use electricity tariff, which is an important control parameter. The control variables are the supply switch to the HPWH and the power from the grid, while the hot water temperature inside the tank is the state variable. The model meets both the HPWH’s technical and operational constraints in providing hot water at a desired temperature and achieves load shifting. This problem is solved using a mixed integer linear program. The results show a 70.7% cost reduction upon implementation of this intervention. A case study is done and the OC shows significant potential in both energy and cost saving in comparison to the digital thermostat controller used in most of the HPWHs on the market. The economic analysis is presented in this paper as well.