Semiconductors tend to be light sensitive. Photons losing their energy in collisions with electrons promote electrons into the valance band where they are free to conduct. Generally this is not desired so things like BJTs are hidden in opaque packaging. 

If you cut the top off a metal can BJT (I used a 2N2222A) then you get a phototransistor. Couple this with an LED and you can get an optocoupler.

I found with a blue LED I could get up to 20uA out with 20mA input. Gain of around 1/1000 isn't great but it's a start. If I used more directional LEDs I expect the gain would be greater. 

I tried a red LED which performed worse. I expect this is because the red LED was less bright in general. The colour shouldn't make much difference as long as its wavelength is shorter than around 1000nm (infrared). Optocouplers generally use infrared LEDs as this will be most efficient (lowest forward voltage).

Adding a simple common emitter amplifier on the output to fix the optotransistor output voltage (avoids having to charge/discharge the transistor output capacitance) I ended up with an optocoupler with around 100kHz bandwidth. It's also nice seeing when it's on.