A system integrating fuel cells with the power system of a chlorine factory that produces hydrogen as a byproduct during chlorine production is proposed. In order to maximize the factory's profit, in this article, a comprehensive optimal power dispatch algorithm (COPDA) is designed in the factory's energy management system. In the proposed COPDA, the power consumption of the factory's electrolyzer, the output power of fuel cells, and the power purchased from the grid are optimized. Furthermore, mixed-integer linear programming (MILP) is utilized as the optimization scheme for COPDA. The nonlinearity between the chlorine production rate and the power consumption of the electrolyzer, and between the output power of fuel cells and the hydrogen consumption is solved with a piecewise linearization scheme integrated with the MILP constraints. Profit maximization using COPDA is conducted in the environment of time-varying electricity prices. To further increase profit, the chlorine factory is arranged to participate in an incentive-based demand response program. The COPDA can further maximize the factory's profit for the incentive-based demand response program.