The optocoupler you've chosen has a phototransistor. You'll need a bidirectional triac driver; like the series MOC30xx (eg.
MOC306x or
MOC302x).
Some in the series can turn on only at zero-crossing; others turn on immediately. The latter can be used for fine-dimming loads (bulbs or motors) but generates lots of noise since large current spikes can occur if turned on midway into the cycle. The former is used for switching on/off but can dim too but only in half-cycle increments (eg. 1/120sec). Since turn on occurs only at zero-crossing there is less noise/spikes and easier on the load.
Also, if the load is inductive, you'll need a snubber resistor/cap.
See attached.
No good at all. The opto's phototransistor is only rated for max. 35VDC (or 6V if reverse polarity), so it will fail as soon as mains is applied.
Pqass has already given good advice
For the TRIAC, yes, you need a box, just to avoid exposed mains terminals, but the heatsink doesn't have to be (and shouldn't be) live. Either use an isolated heatsink mounting kit for the TRIAC, or (easier) get a different one in an isolated package. If the heatsink is accessible it must be grounded for safety.
I only need the circuit to turn On and Off, so the zero crossing will work.
Thank you for the links!