Modern equipment usually suffers from coupling effects of natural degradation and random shocks under dynamic environments which can lead to sudden and unexpected failure. Imperfect maintenance is often preferred over system replacement due to its time and cost efficiency, but the system lifespan may be reduced with increased imperfect maintenance actions. In such cases, it is imperative for decision-makers to make trade-offs between imperfect maintenance and replacement actions. To address this issue, we propose a reliability model for systems subject to multiple dependent competing failure processes under dynamic environments, where several imperfect maintenance actions are performed before replacement. The dynamic environment of the system follows a continuous-time Markov process, and its natural degradation behavior under different environments is controlled by distinct gamma processes. We derive important distributions and expectations to describe system performance, such as imperfect maintenance cycles and replacement cycles, using Laplace transforms. Then, an optimization problem is proposed whose decision variable is the number of imperfect maintenance actions between two adjacent replacements, aiming to maximize the long-term expected profit rate with constraints of availability and expected running time. Finally, a case study of a Micro-electromechanical system is provided to illustrate the effectiveness of the proposed model.