There is no way one can know if you are online ( Available/invisisble ) or offline as long as the person seated next to you or standing right behind you.
But there is a catch. There are lot of available websites through which one can easily find out if a person is online or not or if the person is online and is in invisible mode. Try this yourself if you want to know how they find out about you.
Maybe they know the time you usually get online and if you are in invisible mode, they simply track your yahoo email id and find out if you are online and in invisible model
As of now there is no known solution to block people from checking your yahoo status but if I find any such, I will inform you.
The best you can do is to give them reasons like you weren't infront of PC or that your PC screen was frozen or Yahoo was frozen etc. etc.. :) ( hope these reasons works for you and the person who are searching for you online )
Click on the link below to open the webpage and enter the person's yahoo id you want to know to find the statusLink