Optimal Investment in Prevention and Recovery for Mitigating Epidemic Risks