PIC16f877A: Working in Debug mode not working in Release mode
According to this http://microchip.wikidot.com/mplabx:build-debug
and http://microchip.wikidot.com/mplabx:build-release

MPLABX has separate build processes depending on whether you want to debug your target or run it freestanding. It appears that to run your target  (freestanding) you just press Run Project. According to Microchip this will:

Builds (makes) the project in release mode, programs the target, and releases the device from reset so that the program starts running. The debug tool has no control over the program's execution in this mode.