As voretaq7 notes, the pilots are the first limiting factor here. We can put a submarine crew underwater for 3 months at a time. Could we do the same on a plane? Maybe someday. The International Space Station is an example of what is possible as far as crew rotations. Of course, energy to fly in the atmosphere and external maintenance would pose some problems for an aircraft.
As far as maintenance is concerned, airliners go 500-800 hours between their low level A checks. However, they also undergo routine maintenance at each stop. Mechanical or electronic items that fail are replaced and minor checks are performed. Engines need oil, hydraulic systems need to be replenished.
These are all decisions made as part of the aircraft design process. By making systems more robust, by adding capacity for consumables such as engine oil, these intervals can be extended. Materials such as composites that are less susceptible to corrosion or fatigue can be used. Electric motors need much less maintenance than jet or piston engines, and electricity can come from solar panels.
It really just comes down to the design of a plane. Theoretically, an "indefinite" endurance is certainly possible. It would probably have to be unmanned, but with a robust structural and propulsion design, it could happen. However, everything will fail or wear out eventually, and without a crew or some system to replace components, that will be the limiting factor.
As far as commercial flights, there is a Wikipedia article that lists the longest scheduled flights by distance, aircraft type, and airline (and also the shortest scheduled flights, just because). The longest duration flight is DAL201, Johannesburg to Atlanta at 16 hours, 55 minutes on a 777-200LR (currently the airliner with the longest range).
With aerial refueling, endurance increases. The B-2 has flown missions of at least 25 hours, with a crew of 2. Landing for a fuel stop (but without engine shutdown), the longest mission is 44 hours. The longest training mission ever was 50 hours. The pilots train extensively in order to be able to fly these missions.
The B-52 has a similar mission and has flown missions as long as 35 hours. Despite being a single seat aircraft, the F-117 has made flights of over 18 hours.
Also notable is the Rutan Voyager, first plane to fly nonstop around the world. The crew of 2 took 9 days to accomplish this.
The Solar Impulse plane is currently in development, and has made a flight of 26 hours with 1 pilot.