Maybe we'll give them 1-1 1/2 dozen years then. Maybe the Japanese government (when trying to motivate soldiers to fight the chinese) abolishes the stipend, and says they'll get a lot of riches from exploiting China. Also, their problems will be over sooner, the imperial restoration would happen sooner. How about this PoD, the shogun after hearing about European colonization of somewhere realizes ''I don't want this to happen to me'' and ends Japan's modernization, then the samurai go ''Restore the emperor, end modernization/resume isolation'' Then the emperor does what he did irl.
I think initially, just an asymmetric trade agreement in favor of Japan would start generating some money to pay the army with
''what if''
I can't remember exactly, but I'm pretty sure it was either
Britannica: Tewodros II, A History of Ethiopia (Updated Edition) by Harold Marcus or ''Tewodros as Reformer and Modernizer'' I read that on JSTOR, but it's not there anymore
Again ''What if''
The last time a Japanese ruler said, "Hey, let's invade the mainland, it'll be profitable and you'll all get benefit from this" with the intent of diverting the samurai class's dissatisfaction, over a hundred thousand Japanese soldiers died, Japan was utterly defeated, and the archipelago got thrown back into civil war (Imjin War). Doubtless, that would be brought up in decision making, since it was the last time Japan had fought a war with another nation. Not the most relevant to this discussion, but still an amusing parallel.
Back to the main point, what's the order of this? The shogun tries to end modernization (what you wrote), the samurai overthrow him for the emperor, then the emperor abolishes their stipend to promise they'll make it back after they fight China (which has historically gone not so well for Japan)?
1. Why would the shogun try to end modernization if he's afraid of European colonization? The shogunate was the faction that had more ties with the Europeans and was more active with trying to adopt their technology to avoid being colonized. In fact, that was a major part of why there was discontent against the shogunate and why people were going, "revere the Emperor, expel the barbarians." Why would they try to overthrow him if he's doing what they want?
2. That's OTL. And that took a war to resolve.
As for abolishing the stipend, that caused multiple uprisings (Saga, Satsuma) in Japan in OTL and still took 6 years to finally abolish. It almost bankrupted the state and more than doubled the national debt to crush the Satsuma rebellion. The situation you're proposing has the samurai offer to give up their stipend in return for invading China, which means they'd be giving up their cushy peaceful lives for a chance at riches that requires going to war (with all the disease, death, and discomfort that that entails) for. That alone would cause a rebellion or the complete paralysis of the state. The historical precedent of the Imjin War and how it parallels the situation would certainly not help with such a proposal either.
Aside from getting the army to sign on for this task, there's also the lack of a proper modern fleet. All the ships the Imperial faction had in 1868 amounted to the tonnage of a single French warship at the time. The Empire didn't even have a central navy for the first two years of its existence. It took more than a decade to consider naval expansion (the government had to be convinced that domestic rebellions were no longer the biggest threat to Japan) and then more than a decade to create a fleet that could take on China's on paper.
Korea and Taiwan were not rich at this point in history and trade agreements with them would not have amounted to much. Both were entirely agarian economies that Japan used mostly to feed the home islands, not for trade. But that wasn't as useful until Japan industrialized and moved the economy away from agriculture.
As for your "what if"s, you can handwave the motivations as you please. That's your prerogative. But it won't make sense simply because the historical context doesn't lend itself to supporting those hypotheticals.
Japan between 1840 and 1880 was not in a position to wage wars of expansion overseas. Industrialization was expensive, civil unrest from historical grudges and western influence would see multiple civil wars break out, and the state was focused on internal development to fund expansions of the army, navy, and economy. A large scale war like the Imjin War in that time period would've strained Japan's already precarious economic situation and made it even more susceptible to western imperialism (giving them a casus belli like payment of debts as France did to Mexico). That's why the Japanese government refused to invade Korea in 1873's Seikanron, much to Saigō Takamori's chagrin.
Hell, even into the 1880s, Japan wasn't able to (or wasn't confident that it could) contest China in Korea, as seen in the Imo Incident and failed Gapsin Coup (the latter had Japanese troops supporting the coup).
As stated in this
paper, "During the building of its colonial empire Japan was unable to sustain both its overseas expansion and its economic growth."
So once again, you'd need an earlier PoD to give Japan a navy, which requires enough stability to be able to afford not focus on funding the army to put down rebellions, and an economy that can support war with the mainland without risking economic consequences. Those take time to develop and OTL showed it to be a lot longer than 10-20 years.