As dmckee said, the problem is complex. Fortunately, there are some simplifications that can be made without much damage to the accuracy. I hope I can present them in an accesible manner.
My guess is that since You have constant inlet and ambient temperatures and a target outlet temperature, what You are looking for are the pipe's dimensions and properties (type of material).
At the beginning You can neglect the radiation from the surface - at 500K it barely exists.
As it was mentioned, the easiest way to solve this problem is to compute an algorithm using software like MatLab or Wolfram Mathematica. Also get familiar with dimensionless numbers used in heat transfer theory. Two of them are more important than others - Nusselt number and Reynolds number. Nusselt number is vital for determining forced convective heat transfer coefficients, there are many empirical correlations for Nusselt number available, but they usually depend on the value of Reynolds number. Reynolds number defines whether the flow is laminar, transitional or turbulent. For turbulent flows in horizontal pipe's Gnielinski correlation for convective heat transfer coefficient is quite good. Calculating the heat transfer coefficients You will often have to define the wall temperature. It is generally unknown, it differs not only along the pipe's length but also in the radial direction - it is hotter on the inner surface of the pipe. Since the pipe's walls are usually thin, in Your calculations You can assume that the temperature is uniform along the radius, but You cannot assume that it is uniform along it's length. That's why the easiest way is to solve it iteratively, calculating the fluid's properties after each, let's say 5 cm of the pipe. Each time You can set the wall temperature to
$$\frac {T_{\text{fluid}} + T_{\text{amb}}}{2}$$, which isn't very bad approximation. You must remember though, that $T_{fluid}$ is 500K only at the first step, every next step it should be a result of the previous calculation. You carry on with the calculations unless the temperature of the fluid reaches 330K. Then You count the number of steps, multiply it by 5cm, and the result is the required pipe's length. Of course, at the beginning, pipe's inner and outer diameters shall be assumed as well as the pipe's material (it affects the value of thermal conductivity). Now that You have calculated the length You have to decide if it suits You, and alternatively change the pipe's diameters or material and repeat the calculations until the pipe's length satisfies You.
Three processes are involved:
Conduction: Heat flows from the object to its environment. Removal rate of heat from the interface further away from the object is proportional to the coefficient of conductivity (0.024 for air, 205 for aluminum -see http://www.engineeringtoolbox.com/thermal-conductivity-d_429.html).
Convection: The interface between the object and air is the same, but removal of heat from the interface is by replacing the interface volume, due to the flow of air (e.g: due to wind). Convection is more effective than conduction within the air - hence the familiar habit of blowing on hot food to cool it.
Radiation does not depend on the immediate environment. There is, however, a balance between incoming radiation (from the sun, earth, space etc.) and outgoing radiation (from the object). With very hot objects - radiation heat transfer would be dominant.
Best Answer
http://www.egr.msu.edu/~somerton/Nusselt/
here you can find some formulas for calculating Nusselt, Prandtl, Reynolds, Rayleigh and Grasshoff numbers. Those are important for evaluating conditions in different systems. Numbers will tell you which state of convection is around your geometry (natural, forced, laminar, turbulent, external, internal). For each case there exist some correlation.
More info about Nusselt number and others you can find eg. on Wikipaedia.
After calculating convenient numbers, you can calculate heat transfer coefficient zumbeispiel from Nusselt nuber.