You can set all unused pins as outputs, that avoids any problems. If the pin you're using as an input is having problems, you will need to do 'something' with it - what are you trying to connect to it?, how about posting a piece of the circuit.
I'm not suprised it doesn't work, I don't understand the left hand one at all?, and the right hand one hasn't got any pull-up to enable it to work.
You only need one resistor for each pin as a pull-up, fed directly from the output of the opto-coupler. When the opto-coupler is on, the pin will be low, when it's off the pin will be high - you write your program accordingly.
Here's a quick circuit, the photo-transistor is the one inside the opto-coupler.