First, checkout this answer on the RasPi SE. https://raspberrypi.stackexchange.com/questions/1633/how-can-one-control-ac-power-220v-with-a-raspberry-pi. Avoid using Solid State relays for controlling appliances with motors (cooling fans, winches, ski-lifts, escalators, washer Spin-Cycle, etc), unless the manufacturer says it's ok. Look online for more info on how to mitigate inductive loads with solid-state relays.
I wouldn't use the PasPi pins to directly drive anything over 4mA particularly relays. Use a transistor with kick-back protection (see below).
There is also a RasPi friendly SCR daughter board that allows you to trigger 110Volts. At our local hacklab, we used one of those to trigger a Pop Machine to dispense drinks via RasPi. Works fine and everyone is so far safe.
If you're bent on triggering a mechanical relay, you can use a Power MOSFET like this one FDC6303N to trigger your relay. This FET has built-in protection diode for the inductor kick-back. just watch that your relay voltage and amperage is below the tolerance of the FET. You could use a ULN2000 series Bi-Polar transistor as well (as suggesed. I personally like FETs). There are non-surface mount versions of these as well.
Some Safety notes:
You can use a watch-dog chip to turn off the relay if the RasPi is hung or gone crazy. this means that every few seconds your RasPi will have say to the Watchdog: "I'm still sane" by doing something (send a digital message or flick a pin up/down).
I would use a somewhat-weak (50-100K) resistor to pull the controlling pin of your RasPi in the direction that turns the Relay Off (in-case your system goes to an unknown state and/or the pin floats).
- Make sure the 110-220V stuff (if on the same board) are physically far and separated.
There are examples on the RASPI site for working with the GPIO pins.
Finally, what you're trying to do could obviously be hazardous. This post will by no-means whatsoever guarantee safety and operation. I'm just sharing what I've learned in hopes that with the help of this community, you get what you want. Verify this info on your own, and make your decision at the end.
Best Answer
If safety is a primary concern, rather than build that circuit up, you could consider purchasing a standard AC-input module for about $10-$15. They are UL, CSA, CE, and TÜV safety certified (it's still possible to go wrong and create a dangerous situation, especially if the wiring is sloppy, but less likely).
Best to have someone knowledgeable look it over before you power it up in any case.
The circuit inside the housing is somewhat similar to the one you show, however it will respond much faster.
With regard to the circuit you show the PS2501 has a short-term isolation voltage rating of 5000V RMS. That is adequate to safely withstand the 240VAC mains and most transients that might appear on it.
For safety you need to keep the creepage (surface leakage) distance between input and output leads (of the opto) to at least 8mm and make sure it can never get wet or otherwise contaminated with conductive materials.
The circuit on the low voltage side should be earthed and fuses or other current limiting used so a failure of the opto cannot cause a hazardous condition. R1 and R4 may or may not be acceptable depending on the type. They can certainly burn up under some conditions.
Without an earth connection on the isolated side you are depending on a few mils of plastic inside that opto for safety.
As far as your other questions, the 90V rating is only the output transistor- in operation, it sees only 5V and the 240V input is reduced to the 1.2V the LED needs through the components to the left of the isolator.
All the latter parts are electrically "hot" (including that side of the opto) and need to be well protected against accidental contact.
The capacitor C1 MUST be an X2 type which is a safety certification for cross-mains use. R1 and R2 must be capable of withstanding mains voltage and transients. Vishay VR25, 35 etc. series is appropriately rated.
C1 is what really does the work of dropping the 240VAC down to 1.2V. Most of the mains voltage appears across it. On positive half-cycles the current flows through the LED in the optocoupler, on negative half-cycles the current flows through the 1N4007. The resistors are there mainly to limit the current if powered up when the voltage is not zero.