Buying and selling a bike within a months' long trip is not going to work. Takes time to find a bike, buy it, get paperwork straight, then re-sell, which can be much harder and take even more time. Could take a month just to get a bike on the road. Selling? Never happen.
Renting from a commercial Moto business will be expensive and really no guarantess. Lots of hustlers out there. I recently read a RR from a American couple that rented two bikes out of Lima. The owner insisted on coming as a Paid Guide. The guy was the total crook, lied about everything. Despite this they still had a good but very expensive ride. Beware.
Probably between $50 to $100 a day, based on bike you get. So, at the low end figure $50 X 30 days =$1500 USD. High end = $3000 USD
This would be for a beat on KLR, XR or XT.
Probably your best option is to rent from a fellow traveler who plans on staying somewhere for a while. Have him/her arrange a notarized permission waiver to allow border crossings. Hopefully this would work. I'm can't be sure of this, things change constantly. But even rental bikes from commercial outfits may have problems at borders. These countries to not have reciprocity on import/export rules so each tries to bust the balls of the guy next store. No standard rules back and forth, every country different. The more convoluted and confusing it is the more petty tin pot dictators at the borders can extract bribes and enrich their fifedom.
For sure you could do at least ONE country. I would do Argentina and call yourselves Ewan & Charlie. Easily a month's worth exploring there with a fantastic and wide variety of everything to see. And of course, they love the British!

!Los Malvinas son Nuestras! Seriously, Argentina is the best!
A month long trip is a bad idea. Why bother? Go to the South of France or Spain or Morocco ... or for real adventure, go to Belfast!
If you're paying the big air fare to Lima then make it worth your while. Minimum three to four months is the way to go. Save up, bide you time, do research.
There are plenty of travelers selling bikes there, I'm sure some would rent you their set up bikes cheaper than any commercial moto rental company.