While Shimano Di2 works best if all components are from the same series, you can actually mix the hardware across series. In most cases you can even mix mountain bike, road and gravel components all on one bike. Note that you cannot mix mtb / gravel / road derailleurs.
This page links to the official and up to date Shimano Di2 compatibility charts so you can look up which components are compatible with your system. Click on the link or image below to view the PDF file.