They'd have to perfect everything and hope that the competition blunders somehow.
That's exactly what happened in the 7th gen, The Wii had EVERYTHING going for it; price, popularity, image, games, innovation, etc., whilst Sony had their PS3 blunders; extremely high price tag, bad image, lack of innovation, lack of games, extremely hard to develop for, etc., and the 360 had its fair share as well; the RRoD, lack of 1st party studios, Paid Online, etc.
And it's also what's happening right now in the 8th gen: PS4 has EVERYTHING going for it; 3rd party support, best graphics, great price tag, games, indie support, etc., and the Xbox One has tons of blunders, but it's recovering even faster than the PS360 did, and the WiiU has its blunders that unfortunately aren't as recoverable as the competition's blunders; They can't get rid of the gamepad, they can't make the console more powerful, they can't lower the price tag or they'll suffer losses, etc.
It's important to note though that despite everything that assisted/hurt all the sides in the 7th gen, Nintendo only won by a small margin (15m more than the competition, could shrink to 10m or less), so you'd have to wonder if they'd ever have such perfect circumstances again, and if they'd sell as well as they did.
Here's what they should do to have the best chance:
1.They should redesign the WiiU gamepad in a way that makes it more attractive to those who don't like it and so that the WiiU gets cheaper, and so they got more profits to ready for the next gen.
2.They should better their relationships with 3rd parties: It's been 18 years since the N64 blunder than destroyed the relationships between Nintendo and 3rd parties, some people see this as a curse that'll haunt Nintendo for eternity, others, like me, see that Nintendo CAN indeed repair these broken relationships, and it's vital that they do. They could start by taking their requests into consideration whilst building their next console, like implementing an achievement system and a more robust online experience, not to mention the x86_64 architecture.
3.They should cut the useless gimmicks that only add to the console's price and end up taking valuable construction costs that could've otherwise been used for much more important things. Look, I love the WiiU Gamepad, it's comfy, it's convenient, it has potential. but that's the problem right there: it has potential. What did Nintendo do so far to prove the Gamepad's worth? Maps that could be placed on the big and much clearer TV screen? 2 player modes that could play perfectly fine using split screen on the TV? Video chat that nobody uses which is better off being an optional accessory like the Kinect/PSCamera? Motion sensors that make for awkward games that aren't worth price?
The WiiU Gamepad is amazing, but it should've been an optional accessory. Imagine what it would've been like if the WiiU launched at 350$ with all the extra money they used up on the Gamepad and its R&D and other useless accessories from the Premium set instead used for powering up the console? Their 3rd party situation wouldn't have solved itself, but it would've been a heck of a lot better, because 3rd parties would literally have nothing to lose when they port their games, because porting between 3 x86_64 consoles would be dirt cheap and their ports would actually make profits even if they had low sales. In fact, each port would probably better their 3rd party game, and after a while, They'd have been in a much better position.
4.Nintendo let all the money they got in the Wii/DS era just slip away. Sure they have around 10B$ in assets right now, but they had like, what? 80B$ in the Wii/DS era? Why'd they just waste all that money? They could've used it to handle losses like Sony and MS do, they could've used it to hire better R&D devs, they could've used it to open more 1st party studios! They let all the money they made slip away for crying out loud!
What they should do is harness their profits. They're not poised to make extremely big bucks this gen (Amiibo could go either way, but it wouldn't be enough IMO), so why not just use the money that they get during this gen to build up for a fantastic Gen 9 through better R&D, more first party studios, and expanding their teams that are incompetent at making HD games.
5.Fresh blood is neccessary. I know that Nintendo's already doing that, but they need to do it on a much bigger scale, and it has to be more drastic.
And I don't mean that they should just hire more young devs, they need younger people in their board of directors, which brings me to my next point:
6.They need an overhaul in management and philosophies. No, I don't mean that they should fire Iwata from being CEO, No, I don't mean that they should fire Reggie or Miyamoto or Sakamoto or whatever. I mean that they need to overhaul the management: They need to bring in more Sestern minds. Contrary to popular belief, Western people aren't the plague when it comes to Nintendo. The gaming industry has grown a lot, it's not the same as when Nintendo saved it back in 1985, It's not Japan-centric anymore. It's a global market worth Billions of dollars, and It's Western-centric now. Like I said, I don't suggest that they should fire Iwata and place a random Western guy as the President of Nintendo who could destroy everything that they've ever worked for, no, I mean that, for example, they should place a competent Western video game expert (heck, even Reggie would do!) as the CEO of Nintendo of America, a position that has been far underused and underprivileged ever since it was introduced. Likewise, Nintendo of America should get more privileges, such as playing a major role in the development of their platforms, which would greatly help the consoles' attractiveness to the Western market, and would greatly assist in the repairment of their 3rd party relationships.
7.Modernize. Make the Nintendo Network more robust. Fix the WiiU's issues in a way that'll make the next console start out and launch perfectly.
That's what I have to say on the matter. I know, I should be Nintendo's President :P