I looked around on Miata.net and found this post that explained potential causes for the check engine light (CEL) code P0171.
The post outlined that the easiest fix to check for was cleaning the Mass Air Flow (MAF) sensor, as if the intake is dirty the MAF sensor can eventually provide bad readings to the catalytic convertor and make the fuel-air mixture appear too rich or too lean.
Since the CEL code P0140 was also being thrown, my guess was that it was a potential faulty O2 sensor causing the issue. I first decided to go the cheapest route and purchased the CRC MAF Sensor Cleaner from Autozone for $7.95 at the time and very delicately cleaned the MAF sensor by following instructions in this video. Unfortunately, I did not take any pictures of my effort, but the images, and their captions below, taken by oresk should suffice for instructions.
NOTE: Remember to disconnect the battery before doing any of this.
Figure 1. This is an example of the NB Miata Engine
Figure 2. The MAF Sensor is a square box connected to the intake
Figure 3. Take the electrical connector off carefully without breaking it
Figure 4. The electrical connector is now disconnected
Figure 5. Loosen the bolt and take the intake tube off
Figure 6. Pull the MAF sensor out slowly after removing the two bolts that it may have
Figure 7. Sideways view of the MAF sensor. My engine had the 2 bolts holding the sensor so you need to use the #10 wrench to undo those bolts
Figure 8. The front view of the MAF sensor. The thin vertical line is the sensor. DO NOT TOUCH the sensor.
Spray the sensor using the CRC MAF Sensor Cleaner (mentioned above) from about 15-20 inches away, and let it to dry for about 10-15 minutes.
After the MAF sensor has been cleaned and dried, you can install it back in the same order you had removed it and attach all the bolts back.
If the intake tube area is dirty you can use slight amounts of warm soapy water or just water and a clean microfiber towel to clean it up before attaching the MAF sensor back.
Once I did this, the CEL went away since the battery had been disconnected.
I drove the car for about 10 miles and no CELs were thrown up, so I assumed I needed to wait for the car to be driven about 25-50 miles more.