Theory of open quantum systems