Samurai go obsolete when macemen go obsolete. They're better than macemen, but not that much better; basically, they have a higher chance against muskets, although both will probably loose. When you think the AI is getting near cavalry, riflemen, or grenadiers, I would sue for peace, tech to grens/rifles, and then resume after the swap. If you can manage to be really prescient and sue for peace 1 or 2 turns before the AI gets the required tech, that would be best. If it has grens/cav/rifles, the AI power graph goes up significantly, so it considers itself at an advantage in negotiations, so you won't get as much out of the peace deal. If you can be tricksy and time it before they get the tech, then you can get more stuff out of it in the mean time.
I'd move your CR samurai to grenadiers, and the rest of them to riflemen. Riflemen are better almost all the time, unless you're taking cities. Remember, the grenadier's bonus vs. riflemen only applies if they're on offense, making a rifle a better stack defender.
There are also two related questions I'd start thinking about. First, where are you going to get the cash to upgrade your samurai to grens/rifles. Do you want to upgrade them all? Or even most? If so, that's a hefty sum of cash. Do you have a GM coming down the line? Can you win the economics race? Is it worth it to do so? Second, should you instead build new units instead of upgrading too many of your old ones?
With regards to cash, I actually think the econ beeline could be worth more than the lib beeline, or at least, worth considering (sometimes you can get both). Winning lib gets you a free tech, which I find is often in the vicinity of 3000 beakers (this may change a bit on Epic; I play on normal). If I can get a similar amount of gold from the GM (or even less...ballpark at 2700 gold, simply because I can't think of a better guess), I think that's more valuable, because it is equivalent to more commerce. I rarely have markets/grocers/banks up everywhere at this point, while I usually have libraries, and occasionally universities/academies. 3000 beakers, at +25% from libraries, is 2400 commerce. If I don't have cash enhancing buildings, then 2700 gold, for example, is 2700 commerce.
Of course, this depends on the exact beaker values and the gold you can get for a GM. In addition, a GM needs to be taken to its destination to get you gold, which can take a while, so the rewards of the GM are delayed. Furthermore, if you're using that gold for research, your payoff is again delayed by the number of turns it takes you to go through your gold surplus. So lib is a greater immediate benefit, which is often a better choice (ref. lightbulbing with great people vs. settling them). Since the GM payoff isn't that far away, though, I wouldn't discount it as much as settling a GS.
The other thing about the GM payoff is that if you're using the GM cash for upgrades, you cannot get that value in beakers, which means ou're deciding the land gains from the upgrades will get you a better return in the long run than the research would.
Gong for economics is also trouble because it might pull you off the tech path to grens/rifles, because you need to snag both banking and econ (I don't recall if you've traded for those). If the AI is going for econ, it won't really trade banking to you, either. Normally, you can put off grabing banking/econ/corp for a bit, because you don't get an immediate gain from the techs. Your science cities are busy building observatories and universities, which were just unlocked, and your mil cities are churning grens and rifles. Thus banking, econ, and corp don't get you much; I'd rather build a university over a bank , as I run with a high slider.
I don't think I have the answer for you, and I do think that lib is a sweet, sweet thing, but it's worth thinking about econ. My point basically boils down to this; it's like in trading tech. If an AI will give you 1000 gold for a tech, or the AI will give you a 1000 beaker tech for your tech, take the gold. It's worth more to you, because you can get 1000 beakers for fewer commerce than you can get 1000 gold.
As an aside, the AI rarely realizes this, which is fun when trading
.