Do I need an external oscillator for PIC16F887A?
It doesn't appear to have an internal oscillator capable of generating its own clock, but if you check page 146 of the PIC16F87XA datasheet it shows how you can use an RC oscillator if cost rather than the number of I/O pins is an issue. The PIC Mid-range Family Guide oscillator section includes the following recommendations:


  For REXT values below 2.2kΩ , oscillator operation may become unstable, or stop
  completely. For very high REXT values (e.g. 1 MΩ), the oscillator becomes sensitive to noise, humidity and leakage. Thus, we recommend keeping REXT between 3 kΩ and 100 kΩ. 
  
  Although the oscillator will operate with no external capacitor (CEXT = 0 pF), we recommend using values above 20 pF for noise and stability reasons. With no or small external capacitance, the oscillation frequency can vary dramatically due to changes in external capacitances, such as PCB trace capacitance and package lead frame capacitance.


While the design is based on a relaxation oscillator I found several references to Microchip not committing to an exact time determination formula. However on page 200 of the datasheet you'll find a graph of typical frequencies for several resistor / capacitor combinations. If you're running at 5V it looks like 20pF and a 5.1 kΩ resistor should be close to the mark.

I guess you're using a chip you already have on hand, but the more modern devices include internal clock options that are much more accurate and leave the I/O pins available for other uses. If you won't really need that much speed you could also consider running it as a lower clock rate, as 4MHz is the highest recommended rate and component tolerances may push it over that limit.