This paper deals with a repairable system subject to three types of failures which arrive according to a non-homogeneous Poisson process. It is assumed that the type I failure can be fixed (k-1) times by a minimal repair policy and type III failure is a catastrophic failure and the system should be replaced by a new one. If the failure is of type II and the system is at age t, then it is either minimally repaired with probability p(t) or replaced by a new one with probability 1-p(t). The purpose of this study is to find an optimal planned replacement time by taking into account all of the costs involved (repairs and replacements) and the availability of the system. It is interested in minimizing the total expected discounted cost and maximizing the availability. The existence and uniqueness of the solution of the problem are investigated. Numerical computations are given for illustrating the obtained theoretical results and to study the effect of the parameters of the model on the optimal planned replacement time.