What game modes can I earn XP in?
"In the Heart of the Swarm leveling system, players earn experience while playing Blizzard matchmaking modes and custom games on Blizzard maps."
Quote taken from Heart of the Swarm's experience preview.
Here's what I can add from my own online endeavors:
Yesterday I've played a ranked match, got experience for it. I also went ahead and completed the 3 levels from the new online 'tutorial' they created, got experience for that too.
But it's pretty clear from what Blizzard said, that you'll gain experience for pretty much any game you play online, be it versus AI or players, as long as you're playing on Blizzard made maps.
XP can be gained in multiplayer games only which involve a standard game (aka not a custom game, or what use to be called a 'used map settings' game in Starcraft 1). You can play against computers or other users Ranked or Unranked and gain XP.
Heres is the original announcement during the beta for XP.
There is also many ways to get Bonus EXP which would make leveling even faster!
From the 2.01 patch notes you gain XP for:
playing Ranked and Unranked matchmaking games or when playing Custom Games on Blizzard melee maps.
Full XP will be gained in any game that awards it.