Recommend you check into renting an apt in Madrid and Barcelona. Great rates, more space, a kitchen and sometimes better interaction with locals. Check out aribnb to find opportunities. Anywhere we stay for three nights our first choice is an apt.
The overall pace of your schedule is great. Be sure and max the enjoyment by staying up late and getting into the Spanish frame of mind for their use of time.
Check out the RENFE site, a real pain to use, but offers great price specials. When possible use the AVE, a great experience, buy second class tickets. Check out trip advisor RENFE forum for how to best deal with the renfe site.
the Barceloneta area is convenient to beaches as is the former olympic village. However, it is easy to take the subway to the beaches and common to find folks on the subway in their beach attire. It will be hot, stay hydrated. Take few, if any, valuables to the beach. Also suggest you rent a couple of chairs and an umbrella at one of the many beachside stands/bars.
Definitely stay away from Las Ramblas, a nice place to be pick pocketed.
If you rent apt make sure it has AC!
Have you purchased airfare? If not, then check out option for an open jaw where you fly into Madrid and out of Barcelona. You might consider flying into Granada and working your itinerary in reverse, ending up in Barcelona.
In Madrid we stayed in the La Latina district, kept us close to old town and very much a locals artsy district. If you want to be in the thick of things then suggest staying across from the Prado. Grab an apt with a terrace , makes a great place to enjoy the end of a day with your own bottle of wine, cheese and iberico ham.