Resistor power dissipation when driving optocoupler from ac mains
I do not know if you are connecting this to 120V or 240V ac mains, but this source voltage (U) and the resistor (R) is what defines the current through the optocoupler input LED, not the other way around! 

So for example you need a current of I=20mA with a given U=120V ac mains, then you can calculate R = U/I = 120V/20mA = 6kOhms. The resistor dissipative power will be about I^2*R = 2.4 Watts (It is actually less than that because of AC current). 

(I disregarded the 1.4V voltage drop of the diode as this is negligible compared to the high input voltage U).