Can I replace 11 speed 11-40t with a 11-42t or 11-46t staying with Shimano XT family?
Depends on what derailleur and front rings you have.

The current Deore XT M8000 GS (which we can probably assume you have) specs say:


Max 11-42T cassette for a 2x11 setup
Max 11-46T cassette for a 1x11 setup


Additionally for a 2x11 setup there is a max 10 teeth difference between the front rings.