Optogenetics - How do microbial opsins work?
There is nothing special about the use of rhodopsin when compared to making a cell express any transgene. This question can then be read as:


  What is the process in which a cell population is targeted and implanted with a gene of interest?


There are many ways, which depend on the specific cell type and on whether you want to do it in vitro, in vivo and in which species, and it would be very complex to explain them all in detail here, so I will limit myself to two approaches that are popular when doing optogenetics in rodents: viral infection and transgenesis.

Viral infection uses an inactivated virus to deliver the transgene. Essentially you engineer a piece of DNA with the gene for the bacterial opsin of interest and you put it in a viral envelope, that is a series of proteins that form the "body" of the virus and that contain its genetic material.
You then inject the virus in the desired zone (e.g. in a specific brain nucleus) and wait for it to infect the cells around the injection site. A week later those cells will express the transgene. 

For (at least, I think) historical reasons the first type of viruses used for this approach were lentiviruses. These, however, are a tad more complex to handle (especially as they require specialised rooms where they can be handled safely) so adeno-associated viruses (AAV) are becoming more and more popular.

Note that the virus is inactivated, that is, it cannot replicate, just infect the cells around the infection site, but it will not be able to spread around. This is both for safety reasons and because you want the infection to be confined to the specific region where you injected the virus.

As I was saying before, instead of putting a bacterial opsin you can put whatever gene of interest, the procedure is the same. As for the opsins, the first two that were used were the channelrhodopsin-2 (ChR2), a channel sensitive to blue light and that can be used to depolarize (=excite) the cells and the halorhodopsin (NpHR), a chloride pump sensitive to yellow light that will, conversely, hyperpolarize (=inhibit) the cells.
There are nowadays tens of variants of these and other opsins that can be used to drive cell activity with lights. Many of these are described in this (beware! Quite technical) review:

Optogenetics in neural systems - Yizhar et al., Neuron 2011

Transgenesis works instead by generating an animal that carries the opsin (or any other gene) in its DNA. This can be done in various way, such as by microinjection of embryonic stem cells carrying the transgene.

You can find a fairly detailed explanation of the process here: Transgenic Cells and Gene Knock-outs, well summed up by this figure (taken by the same page):

Transgenic mice generation http://9e.devbio.com/images/ch02/wt020302-2.jpg

But how do you get cell-type selectivity?
In front of the gene for the opsin you also will have to put another sequence, called promoter. The promoter is a sequence that is specific to each gene and that is used to determine which genes a cell will or will not transcribe. For instance, the promoter for the gene coding for a protein only present in muscles will be used by muscle cells but not by neurons. You can even get more specific, for instance by using promoters that are typical of a subset of cells and not other (e.g. glutamatergic neurons use a different set of promoters than GABAergic neurons, although these two sets will -at least in part- overlap). However, this means that if you want to change the cell type you are working on you will have to change the DNA vector you are using.
A commonly used approach to avoid this is that of using Cre-dependent vectors (note that this can be used both for viral infections or for transgenic animals).
Essentially you will have a mouse line which expresses a protein derived from the P1 phage, called Cre recombinase, only in the cell type of interest (again, using a specific promoter). Cre has the property of cutting DNA next to specific 34 base-pair-long sequences called loxP (with sequence ATAACTTCGTATAGCATACATTATACGAAGTTAT). Essentially, if you have loxP-[some sequence in the middle]-loxP and Cre recombinase is around, it will cut away the sequence in the middle, leaving only a loxP sequence.
Hundreds of different Cre-expressing mouse lines are commercially available nowadays, to target many different cell types in different organs.  

Now, you just need a construct that allows you to express the opsin in a Cre-dependent manner. This is what was done by the group of Hongkui Zeng, and reported in this paper:
A toolbox of Cre-dependent optogenetic transgenic mice for light-induced activation and silencing. - Madisen et al., Nat. Neurosci. 2012

Without going into too much details, the idea is to flank a STOP sequence with two loxP sites. This will block transcription (that is what a STOP sequence does) unless Cre-recombinase is present.

Essentially:


Source: myself, CC-by-sa licensed, feel free to reuse it

Note that in the scheme, ROSA26 is an ubiquitous promoter, that is, a promoter used by all cells, so in this case the specificity is given by expression of Cre recombinase and not by the promoter of this construct. Also, a fluorescent reporter (e.g. GFP) is inserted to be able to visualize where the opsin is expressed.

By breeding these mice with the Cre-line(s) of your choice you can then express the opsins in the cell type of your interest.