• Develop a systematic approach to compute the levelized hydrogen production cost (LCOH) under dynamic electricity prices and under different process efficiencies and capital costs. To enable this, we have developed a comprehensive computational framework that integrates detailed process simulation models, microkinetic models (informed by density functional theory), and a multi-period optimization model. This framework is used to determine the optimal sizing and operating strategies of a flexible electrification unit that is compatible with a methanol synthesis process and that is able to respond to dynamics of electricity prices. Our analysis reveals that the economic viability of the proposed approach highly depends on the flexibility of the process and on the market conditions. Specifically, when the system is non-flexible (and cannot adjust operations in response to electricity markets), the electricity cost contributes more than 60% of the total cost and the overall process is not economically viable. On the other hand, when the system is flexible (and can respond to dynamic electricity markets), the electricity cost almost collapses to zero and the overall process is not viable. In comparison with sourcing hydrogen entirely from SMR, implementing the flexible electrification unit leads to a 62 million USD/yr cost reduction for a methanol plant with a capacity of 1 million tonne/yr. The payback period of such retrofitting project is less than eight years. Moreover, we observe that the competitiveness of the electrification unit is sensitive to the natural gas prices. Our analysis also reveals that lowering the capital investment of electrolyzer equipment is more impactful than increasing electrolyzer efficiency; this is important, because the cost of electrolysis units can potentially be decreased as more units are manufactured and deployed (under ongoing hydrogen initiatives). Finally, our analysis reveals that the levelized cost of hydrogen (LCOH) using a flexible electrolysis unit that participates in real-time electricity markets can be as low as 0.91 USD/kg, which is 31% lower than the LCOH via SMR under current natural gas prices. This result is surprising and indicates that there can be tangible benefits of producing hydrogen by exploiting time-varying electricity prices and that such benefits can be exploited for other hydrogen-based processes. All market/process data collected and models developed in our study are shared with this manuscript; these can be used to reproduce the results and to conduct additional studies on the potential of electrifying methanol production and other processes.