It's like. first you put together a P type and an N type.
P type has lotsa holes. N types has electrons.
When you first put them together (at the junction only) -> electrons from the N-type jump into the P type and fill up the holes. This makes the N-type positively charged and the P-type negatively charged at the junction. Now when you have two charges, an electric field is produced that goes from positive to negative right? Any electron that goes into this strong field will now be pushed towards the positive side (which is the N-type at the junction).
Now when you shine light at the solar cell, electrons from the junction region will be knocked out by something similar to the photoelectric effect, that is, they get some energy and they 'jump out' - straight into that electric field. The electric field pushes them into the N-type and causes the electrons on the other side of the N-type to 'squeeze' into the wire and to the battery.
It's better with a picture i guess.