You can check through all the way to LAX no problem. If it's one PNR, it should go all the way automatically (though one should always double check). If two PNRs, you will have to tell them to check to LAX and show your other itinerary.
There is no customs or border control of any kind between Italy and Spain, as they are both Schengen countries, so you will just walk right off into the general departures area, most certainly in T4. Just follow the signs to your gate where you will have to take a tram to T4S where you will pass the exit controls and get your passport stamped. You should even have enough time to check out the Velázquez lounge at that point. Do remember that the US flights have an extra layer of security so you will have to get your documents checked again and there is the posibility of an annoying secondary screening so leave an extra few minutes just in case.