This paper studies the problem of incorporating both learning and forgetting in setups and production into the dynamic lot-sizing model to obtain an optimal production policy, including the optimal number of production runs and the optimal production quantities during the finite period planning horizon. Since the unit production cost is variable due to the effects of learning and forgetting, the first-in-first-out (FIFO) inventory costing method is used in our model. After deriving the relevant cost functions, we develop the multi-dimensional forward dynamic programming (MDFDP) algorithm based on two important properties that can be proved to be able to reduce the computational complexity. A numerical example is illustrated and solved using our refined MDFDP algorithm. The results from our computational experiment show that the optimal number of production runs decreases with the increase of the learning or forgetting rates, while the optimal total cost increases with the increase of one of the above four rates. Production learning has the greatest influence on the optimal total cost among the four parameters. The interactive effects of five demand patterns and nine relationships generated by the four rates on the optimal number of production runs and the optimal total cost are also examined.