This book presents broadly applicable methods for the large deviation and moderate deviation analysis of discrete and continuous time stochastic systems. A feature of the book is the systematic use of variational representations for quantities of interest such as normalized logarithms of probabilities and expected values. By characterizing a large deviation principle in terms of Laplace asymptotics, one converts the proof of large deviation limits into the convergence of variational representations. These features are illustrated though their application to a broad range of discrete and continuous time models, including stochastic partial differential equations, processes with discontinuous statistics, occupancy models, and many others. The tools used in the large deviation analysis also turn out to be useful in understanding Monte Carlo schemes for the numerical approximation of the same probabilities and expected values. This connection is illustrated through the design and analysis of importance sampling and splitting schemes for rare event estimation. The book assumes a solid background in weak convergence of probability measures and stochastic analysis, and is suitable for advanced graduate students, postdocs and researchers.