This paper proposes a generalized replacement model where a deteriorating system has two types of failures and is replaced at the Nth type I failure (minor failure) or first type II failure (catastrophic failure) or at the working age T, whichever occurs first. The probability of type I failure and type II failure is permitted to depend on the number of failures since the last replacement. These systems can be repaired upon type I failure, but are stochastically deteriorating, i.e., the lengths of the operating intervals are stochastically decreasing, whereas the durations of the repairs are stochastically increasing. The expected cost rate is obtained. The optimal N* and optimal T* which would minimize the cost rate are discussed. Various special cases are considered. Finally, a numerical example is given.