From an enterprise perspective, one key motivation to transform the traditional IT management into Cloud is the cost reduction of the hosted services. In an Infrastructure-as-a-Service (IaaS) Cloud, virtual machine (VM) instances share the physical machines (PMs) in the provider's data center. With large number of PMs, providers can maintain low cost of service downtime at the expense of higher infrastructure and other operational costs (e.g., power consumption and cooling costs). Hence, determining the optimal PM capacity requirements that minimize the overall cost is of interest. In this paper, we show how a cost analysis and optimization framework can be developed using stochastic availability and performance models of an IaaS Cloud. Specifically, we study two cost minimization problems to address the capacity planning in an IaaS Cloud: 1) what is the optimal number of PMs that minimizes the total cost of ownership for a given downtime requirement set by service level agreements? and, 2) is it more economical to use cheaper but less reliable PMs or to use costlier but more reliable PMs for insuring the same availability characteristics? We use simulated annealing, a well-known stochastic search algorithm, to solve these optimization problems. Results from our analysis show that the optimal solutions are found within reasonable time.