I ride a 2021 Trek Emonda SLR 8 (lightweight, no electronics) with a R 9100 Group: 50/34 teeth in front and 11/30 teeth in back on my cassette. Would like to upgrade to an 11 - 40 teeth cassette (Shimano XTR CS M9001). I know I would have to add a long cage rear derailleur. Should I buy a: Shimano XTR RD-M900 11 speed long cage SGS shadow plus rear derailleur? Would I need a different set up for the brake lever shifter? Thanks in advance for your advice and suggestions.
RD-M900 is old, you mean RD-M9000. There is no native compatibility of any kind between 11-speed STIs and Shimano mountain 11 rear derailleurs. You could do this with a Jtek Shiftmate 8 and RD-M9000-SGS or RD-M8000-SGS.
Since we're living in the age of attainable 30-46 cranks and road derailleurs that can handle 34t, it may be worth considering if keeping the same high gear but dropping the low is really the best approach. Along with the range come a lot of tradeoffs, and there aren't a lot of riders who could get utility out of the low gear in question here (34t front, 40t rear, approximately 22-23 gear inches, which is almost identical to 30t front, 34t rear) who are also going to get utility out of the 50/11, or really the 50t at all compared to the alternatives.