The potential energy in this case should be $U=+\vec{m}.\vec{B}$, hence the potential energy is minimized, as it should be. Here is the explanation:
Let’s look at the derivation of interaction energy between magnetic dipole and magnetic field carefully. The dipole energy $U=-\vec{m}.\vec{B}$ is derived using principle of virtual work with an assumption that the dipole moment is constant, and thus it’s self energy is permanent. However, if the dipole moment is allowed to change as in this case, the self energy of the dipole is no longer permanent. We can imagine it as the $\frac{1}{2}LI^2$ energy for the case of a current loop, if we change its dipole moment, its internal energy will also change. So for the case like this, the self energy can be extracted into mechanical energy. If we take into account the additional work to change the self energy in the principle of virtual work we will end up with $U=+\vec{m}.\vec{B}$. We can always calculate the work $\int \tau d\theta$ to change the orientation of the dipole. However in this case the dipole moment is not permanent, so its magnitude will be be different for different orientations. Thus the work calculation will be messy, but there is an easy way to do that. We can use some sort of "battery" to keep the dipole moment constant and calculate the work using $−\vec{m}.\vec{B}$. At the end of the process we put back all the energy given/stolen by the battery, which means I changed back the dipole moment to the value it should have been if the battery was not there. In other words I already get rid of all the influences of the battery. The work done by the battery turns out to be $(−2\vec{m}.\vec{B})$, then we get
$U=-\vec{m}.\vec{B}-(-2\vec{m}.\vec{B})=+\vec{m}.\vec{B}$
We can also get the same $U=+\vec{m}.\vec{B}$ if we calculate the total electromagnetic field energy, some details of the derivation is in my blog:
http://emitabsorb.wordpress.com/2011/08/21/m-b-or-m-b/
Magnetic field does no work on a proton, then how do we define potential energy?
Yes the total kinetic energy of the system is conserved, but we can separate it into parts. For example we can lump together the kinetic energy due to $v_x$ & $v_y$ and give it a name say $U_1$. The change in $U_1$ will affect the particle’s movement in $z$ direction, thus we can say that $U_1$ is the potential energy for $z$ direction. In this case we would like to know the tendency of the proton’s angular revolution velocity to align or counter-align with the magnetic field, so we lumped together part of the kinetic energy and magnetic field energy. As how it is derived, this energy can be written as $\tau=-dU/d\theta$. Thus if the lumped energy is not minimum, there will be torque perpendicular to $\vec{B}$.
So why don’t we also use $U=+\vec{m}.\vec{B}$ for the case of permanent dipole since it is the actual total energy with self energy already included in it?
Yes it is true that the right total energy is $U=+\vec{m}.\vec{B}$. But in this case the potential energy, the one that tends to minimize itself is $U=-\vec{m}.\vec{B}$. The part of energy that can minimize itself is the one that can be written as $F=-\nabla U$, that is to say the force will tend to any particle affected by the potential to the place where $U$ is lower. For example, consider a system of an earth and a moon orbiting it. Then suddenly the earth becomes twice as big as before with the same mass. We know that the self gravitational potential energy of the earth is changed, but it leaves no effect on the moon. So in this case the self gravitational potential energy of the earth is not a potential energy for the moon.
Now the only problem remaining in the permanent dipole case is that besides the $–\vec{m}.\vec{B}$ part which can change back and forth with mechanical energy, the remaining $+2\vec{m}.\vec{B}$(part of it is from the dipole’s self energy, and the remaining is from the self energy of the constant $\vec{B}$ field provider) part also changes mysteriously and which means the energy is not conserved. To save the principle conservation of energy we can always invent a new kind of energy so that the $+2\vec{m}.\vec{B}$ is not missing or being created freely but instead it is just changing its form between electromagnetic energy and this new energy. But I think it is not necessary, because what I was doing is not to protect the principle of conservation of energy, but instead to protect the field energy interpretation. Actually the field energy is also derived using the principle of virtual work in the first place, but in this case the increase in the total field energy is not equal to the decrease in mechanical energy. Thus for the case of permanent dipole I think the field energy interpretation is no longer valid. If we stick to the definition $F=-\nabla U$ , these difficulties would never occurs.