Can 8051 pins work as inputs or outputs at the same time in a program?
Microcontroller pins are typically input or output.  When configured for output, there is a SFR (special function register) for that port that controls what levels the pins on that port are set to.  When configured for input, the pin values show up on that same SFR.

In the example you gave (interfacing with a 16x2 LCD), P1.0 would spend most of its time as an input, and the microcontroller code would wait for the busy flag to clear.  When the microcontroller detects the flag has cleared, it would switch the direct of P1.0 to an output, send the commands and data, and then switch back to an input.