American Water Works and Essential Utilities are merging in an all-stock deal that will create a public water utility worth about $40 billion.