Systems commonly operate under time-varying environmental condition (EC). Since the EC can affect the degradation process of a system, maintenance planning can be quite challenging. This study focuses on a case where the evolution processes of the system degradation and the EC are governed by Markov processes, for which the transition rate matrix of degradation states varies with the EC. To maintain the system, an inspection/maintenance policy is adopted, where a maintenance action is carried out immediately when a failure occurs during an inspection interval or upon an inspection epoch when the system’s degradation state reaches a certain threshold. Imperfect maintenance (IM) and replacement are considered in this study, where a certain number of consecutive IM actions can be carried out before each replacement. We first derive the long-run average cost based on the semi-regenerative properties of the system, and then jointly determine the inspection interval, preventive maintenance threshold and number of IM actions before a replacement by minimizing the long-run average cost. A numerical study is conducted to demonstrate the proposed maintenance policy.