If just like to add to the answers here and address a few inaccuracies made about air cargo. What you ask is true, some of the oldest aircraft out there are flying cargo, and most of the answers here are accurate, but some things are based on false assumptions.
The question mentions full size airliners so I am focusing on that. I use FedEx as an example because I'm most familiar with their system. Some things that apply to a large cargo-only carrier may not apply to other parts of the industry.
To clear up a misconception:
Efficiency and reliability are just as important in freight
Fuel burn and cost to operate are just as important Freight operators are no less concerned with the cost of flying and upkeep of their aircraft than the passenger companies. When fuel costs go up it affects them the same as everybody. When fuel prices soar the carriers often implement "fuel surcharges" on top of their regular pricing to help make up the cost. They want the most efficient aircraft they can fly. It's harder to make money if your planes are gas-guzzlers.
Keeping planes in service is just as important Flight delays are just as costly for freight as passengers. Some have pointed out that the inconvenience to passengers has a higher cost to the passenger industry. Not from the freight operators' point of view. They don't want planes broken down any more than the passenger airlines. Being stranded as a passenger is much more of an inconvenience than not receiving your Amazon order. But when you delay a passenger flight you have hundreds of unhappy customers. When a freight flight is delayed there could be thousands of unhappy customers. Some of those customers are very large shippers. If you screw up too many times they may jump ship for another carrier. Losing a big source of revenue like that can have quite a sting financially.
There's more than just airside. For the passenger airlines that move freight and other airport to airport services mechanical delays impact their schedules. But for freight companies that also deliver the freight there is an entire network of employees, much larger than the airside component, that can be left unproductive. I work as a driver and when one of our flights comes in late for mechanical reasons (or any reason) there are 50 of us and 10 or so handlers and sorters standing around on the clock twiddling our thumbs. Our ramp serves 3 large and 4 small stations, so that one late flight can mean overtime for a couple hundred people.
Reasons why older aircraft remain in freight service longer:
Longer life span due to different patterns of use
Cargo aircraft spend more time on the ground. On average passenger airlines have an easier time keeping their aircraft busy. The difference may not be as much as some suspect, though, at least in the case of FedEx. It's hard to find solid numbers on this. Taking a look at flight histories on flightaware of a random sample of FedEx planes and comparing them to similar passenger airliners I found that the passenger aircraft made about 6-8 flights per day whereas the FedEx planes were making 4-6 daily flights. An aircraft on the ground is still not making money. This is no less true for a freighter than a passenger plane.
Fewer short hops The advantage of air freight is that it can cover long distances in a short time. For shorter distances freight can be moved by truck in a similar time for a lot less money. Airlines often make several short hops to keep the seats full. Inter-continental transport is where the air advantage is truly significant. Air is often the only way to move freight in a timely manner. The wear and tear on a plane depends much less on the time or distance it flies. The biggest factor for airframe longevity is pressurization and depressurization cycles. The most wear and tear on engines, brakes, undercarriage, etc come at takeoff and landing. So the longer the flights the longer a plane will last.
Passenger comfort
Passengers prefer newer planes Whether it be the perception of more safety or the greater comfort of newer, quieter aircraft or the bells and whistles often built into newer planes, passengers would rather fly on newer aircraft. Freight doesn't care so much.
Interior wear and tear One place where aircraft have a lot of wear is the interior. This is mostly cosmetic, but seat cushions sag, upholstery wears out, windows get scratched and yellowed. These things can be repaired, of course. But there comes a point when it's time to retire it, but the airframe still has many years left in it. Freighter conversion is often the best option.
Growth and availability
Regulation Up to the 1970's the air freight industry was almost an afterthought. Airlines were heavily regulated by the Civil Aeronautics Board. The board controlled routes and pricing. They also regulated who could fly airliners. Many believed the CAB was overly focused on passenger service and air freight in the US floundered. Even in this situation, the airlines began buying dedicated freighters. The 747 was designed around the concept of being a freighter. The cockpit was put on top to make it easier to load freight containers resulting in the famous "hump."
Deregulation When FedEx was formed in the early 1970's as a freight only airline they started out with a fleet of small Dassault Falcon 20 jets. By the late 70's they had outgrown the Falcons, but were still not able to move to bigger aircraft due to regulations. In 1977 the air freight industry was taken from CAB control and deregulated. There was suddenly a need for larger freighters. The handful of companies manufacturing airliners can only make so many planes a year, so they began buying passenger 727's and DC-10's as they became available and converted them to freighters. Fortunately for them deregulation hit Branniff Airlines hard and they soon folded making their large fleet of 727's available for freight conversion. FedEx flew these 727's long after the passenger services retired them. Several of the DC-10's are still flying today.
Rapid growth FedEx fleet of dedicated freighters is the 5th largest in the world, including passenger lines. The industry expanded rapidly and the passenger airlines had a head start on aircraft purchasing. The freight services joined the new aircraft purchase game. FedEx was the launch customer for the newly minted MD-11, getting the first six aircraft off the line. They have orders still pending for new 777's and were one of the first to order the A-380, although the economic downturn of 2008 caused them to cancel that order and change it to 777's. But aircraft are built slowly and there are a lot of airlines needing them. To keep up with the needs for large freighters they can't afford to let go of the DC-10's in the fleet. The need for efficiency still affects freight operators so they had their DC-10's upgraded to MD-10's which only require two pilots. As they are able to replace them with newer, more efficient aircraft they will eventually be able to send the DC-10's to their retirement homes in New Mexico.
Unable to find any good data on number of flights and flight hours, I got creative. This is really unscientific, but I looked up flight histories month to date on 6 random similar aircraft (B777) from United Airlines and FedEx. Here is a table of the results:
I was a bit surprised that the number of flights were so close. The UA aircraft spent slightly more hours in the air and the FedEx aircraft spent slightly more time on the ground
Like I said, such a small sample from two airlines is not very scientific. I'm not sure if this would bear itself out over the entire fleet, but I can't find numbers anywhere.