The cost reduction of hydrogen refueling stations (HRSs) is very important for the popularization of hydrogen vehicles. This paper proposes an optimized operation algorithm based on hydrogen energy demand estimation for on-site hydrogen refueling stations. Firstly, the user’s hydrogen demand was estimated based on the simulation of their hydrogenation behavior. Secondly, mixed integer linear programming method was used to optimize the operation of the hydrogen refueling station to minimize the unit hydrogen energy cost by using the peak–valley difference of the electricity price. We then used three typical scenario cases to evaluate the optimized operation method. The results show that the optimized operation method proposed in this paper can effectively reduce the rated configuration of electrolyzer and storage tank for HRS and can significantly reduce the unit hydrogen energy cost considering the construction cost compared with the traditional method. Therefore, the optimization operation method of a local hydrogen production and hydrogen refueling station proposed in this paper can reduce the cost of a hydrogen refueling station and accelerate the popularization of hydrogen energy vehicles. Finally, the scope of application of the proposed optimization method and the influence of the variation of the electricity price curve and the unit cost of the electrolyzer are discussed.