First-principles energetics of water clusters and ice: A many-body analysis