Optimal Dynamic Contracts with Moral Hazard and Costly Monitoring