I know that you can play Minecraft with friends over Wi-Fi and that somehow you can play over Xbox but it is free with Xbox live
Everyone who wants to play together must create a Microsoft account (Xbox live), add each other as friends, then one must start a world and everyone should be able to join the said world
You only have to pay for playing online on the consoles
So in order to be able to play online in the case of Xbox, you would need an Xbox gold membership
PS all minecraft versions except the Java edition are crossplay compatible
So I can play Minecraft PE with friends for free
Yes
And with Xbox you have to pay something?
Yes generally for all consoles only the windows 10 edition and the pe edition can play with each other free of charge