as ginnu pointed, you need a valid H1-B or EAD to work legally. However if your I485 is pending your status in the country is legal, until a decision has been made on your petition.
However, if you are in a situation where your H1B is going to expire soon and if you are past the 90 day mark after filing your I765 application, you can approach the local INS office and obtain an interim-EAD card.
Hope this helps. Good Luck!