Man, I gotta believe it would be cheaper/easier to just find the 540i you want with a manual.
It isn't simply just changing the tranny...there are software headaches and reprogramming that you need to do as well. I don't know what you consider as being expensive but I gotta believe the cost of this versus finding a manual in the first place would be prohibitive. BMWs are expensive...that is just the cold hard truth of the matter.
However, wagon's were not offered with a manual as far as I know (in the US) but automatic transmissions are funny things. About half the time, they are very easy to fix and the other half, they are a nightmare to the point where it would be easier to replace the unit.
It could be as easy as changing the fluid in your tranny.