This paper presents a novel energy management control system for green hydrogen production using multi-timescale cost optimization. The proposed approach optimizes the cost of the hydrogen generation, including day-ahead hydrogen target decision, intraday energy scheduling, and hydrogen target correction with forecasting errors. A grid-connected solar-based electrolyzer system with green energy market interaction capability is used for the study. The energy management control incorporates a dual-mode controller to regulate the optimized scheduling of the energy of the electrolyzer and grid-connected inverter with the maximum power point-enabled control for solar arrays. The hydrogen day ahead target is decided by optimization algorithm using solar forecasted data and day ahead green energy market tariff. Based on the hydrogen target and control mode, the proposed algorithm optimizes power references for the grid-connected inverter or the electrolyzer, while another one balances the DC link voltage. Additionally, factors such as forecasting errors, different control modes, unplanned grid interactions, electrolyzer module efficiency, and hydrogen target updated for each segment are considered to enhance system performance. The optimization results indicate that the proposed control system could reduce hydrogen generation costs up to 9.94%. The fixed grid control mode outperforms the fixed electrolyzer control, showing annual cost advantages between 2.81% and 11.36%. These advantages depend on factors such as the solar photovoltaic profile, forecasting errors, and grid tariff variations. MATLAB simulations validate the effectiveness of the stable DC link control and the proposed optimization approach in optimizing the cost of green hydrogen production.