Actually Star Trek *does* touch upon the subject of religion multiple times. Religion does indeed exist - but since Star Fleet regulations does not allow religion to influence it's operations, we rarely see it manifested in the series, other than as a convenient plot device. It's just simply not a big factor of the daily life on the Enterprise.
Matter Replication and Transmutation, and by extension nearly unlimited energy, is indeed essential for a Star Trek society. When nearly everything* can be provided on an when-I-need-it basis, capitalism does not work, since capitalism require scarcity.
As for how Earth could be united in a unified secular government, well, the official explanation is that thanks to Cochrane inventing the warp drive reactor in the mid 21st century, Vulcans appeared and helped the Earth gradually prepare for their new space age. It is not unthinkable that Earth itself will be run by a single government when you have humans on around 20 000 other planets, owned by the federation coalition. And while one shouldn't underestimate humanity's ability to quarrel with each other, one should neither ignore the xenophobic effect created when outsiders show up - especially if those outsiders are far more technologicly advanced than us.
* The only thing lacking would be living matter such as pets and humans.