This paper examines the joint optimization of production and maintenance planning for a single-machine deteriorating system. To achieve optimal performance and meet customer demand at the lowest cost, manufacturing companies need to carefully plan production and maintenance, considering various factors such as time, cost, output levels in any period and its impact on machine deterioration. In this research, we attempt to plan the production and maintenance process for a single-machine single-product system over multi-period. The machine has two operational states during production and gradually deteriorates as it ages. Maintenance operations restore the machine to healthy state and reduce the probability of producing defective products. We model the problem using the Markov decision process and employ the value iteration algorithm to determine the optimal policy, i.e., the best actions to take at each decision epoch. We evaluate the model's effectiveness by solving a numerical example and analyzing how changes in different parameters affect the results. The findings reveal the relationship between various parameters and the average cost rate. Changes in the mentioned rate due to changes in setup cost and the probability of producing conforming products are almost uniform without any drastic fluctuations. If the production cost of each item exceeds a certain threshold, the company's obligations are not enforceable.