A major long-term goal of systems neuroscience is to identify the different roles of neural subtypes in brain circuit function. The ability to causally manipulate selective cell types is critical to meeting this goal. This protocol describes techniques for optically stimulating specific populations of excitatory neurons and inhibitory interneurons in vivo in combination with electrophysiology. Cell type selectivity is obtained using Cre-dependent expression of the light-activated channel Channelrhodopsin-2. We also describe approaches for minimizing optical interference with simultaneous extracellular and intracellular recording. These optogenetic techniques provide a spatially and temporally precise means of studying neural activity in the intact brain and allow a detailed examination of the effect of evoked activity on the surrounding local neural network. Injection of viral vectors requires 30-45 min, and in vivo electrophysiology with optogenetic stimulation requires 1-4 h.