Microsoft only ever came out of the red once in the entirety of the Xbox1's life. That was the month Halo 2 came out. They made $60-70 million dollars. Sounds good! Except most of their financial quarters show losses in excess of $300 million.
To put Microsoft's only profit in perspective, Nintendo has received $120 million + in sales REVENUE (always be sure to know the difference between revenue and profit) from the Brain Training games. Considering that I doubt the game's development budget, advertising, packaging and shipping costs $20 million dollars all combined, Nintendo has profited more than $100 million dollars just on the Brain Training games.
And to answer your other question, Nintendo actually does sell their consoles at a loss at times, but I believe they make the loss per console less than the price of a game. So they sort of still don't sell at a loss. Kinda like the way celery has negative calories (not really, but your body expends more energy attempting to get the energy from celery than celery gives you in return. Fun fact.)
Another fun fact! If you combine just the worldwide million selling titles the DS, you almost reach $1 billion in sales revenue. Meaning that with the other titles included, the DS is already a billion dollar industry unto itself.