In this paper two similar models for the maintenance of a production-inventory system are considered. In both models, an input generating installation supplies a buffer with a raw material and a production unit pulls the raw material from the buffer. The installation in the first model and the production unit in the second model deteriorate stochastically over time and the problem of their optimal preventive maintenance is considered. In the first model, it is assumed that the installation, after the completion of its maintenance, remains idle until the buffer is evacuated, while in the second model, it is assumed that the production unit, after the completion of its maintenance, remains idle until the buffer is filled up. The preventive and corrective repair times of the installation in the first model and the preventive and corrective repair times of the production unit in the second model are continuous random variables with known probability density functions. Under a suitable cost structure, semi-Markov decision processes are considered for both models in order to find a policy that minimizes the long-run expected average cost per unit time. A great number of numerical examples provide strong evidence that, for each fixed buffer content, the average-cost optimal policy is of control-limit type in both models, i.e. it prescribes a preventive maintenance of the installation in the first model and a preventive maintenance of the production unit in the second model if and only if their degree of deterioration is greater than or equal to a critical level. Using the usual regenerative argument, the average cost of the optimal control-limit policy is computed exactly in both models. Four numerical examples are also presented in which the preventive and corrective repair times follow the Exponential, the Weibull, the Gamma and the Log-Normal distribution, respectively.