How to detect pin state change in pulled up pins
You can connect the emitter of the output side of the optocoupler to the ground of the processor, and the collector of the output side to the IO pin of the processor, then this should give you the behaviour you want.

When the transistor conducts, it will pull down that processor's internal pull-up resistor to down to a little bit above ground, but it should be low enough to register as a logic zero.  You can find the actual voltage in the datasheet as V_CE(SAT), which is around 0.2 volts for the PC817.  

You will no longer have your own pulling resistor of your own at all, since the processor has one already.  

What I had in mind was this: