Understanding optimal replacement practices is essential in milk production management. In this study, we produced a stochastic dynamic optimization model that included the risk of diseases. Moreover, the study took into consideration the genetic production capacity of a cow and the uncertainty related to it. We determined the optimal replacement policy separately for Ayrshire and for Holstein-Friesian Finnish herds. The need for veterinary treatments and the probability of involuntary culling were estimated from the Finnish dairy herd health recording system. We found that the portion of involuntary culling was approximately 50% of present disposals. The need for veterinary treatments and the probability of involuntary culling were higher for Holstein-Friesian than for Ayrshire cows. Regardless of health status, only the oldest cows with low production capacity should be disposed of intentionally. In the postoptimization steady state, the mean parity was 3.8 and 3.7 for Ayrshire and Holstein-Friesian herds, respectively. Under current management practice, the mean is only 2.3 parities. Preventing premature culling of dairy cows is important to improve the possibilities of breeding selection and the economic performance of milk production. The expected net present value of a cow was slightly higher in Ayrshire than in Holstein-Friesian herds. The results indicate that in the long run, it is worth paying attention to the health status and longevity of a cow as well as to its high yield.