Me and 5 of my friends will be staying in Madrid for 3 nights. For one of the days, we were hoping to visit a vineyard, where we can hang out for a few hours and taste some wines (nothing formal). Are there any nearby that we can get to through public transportation?
Have you looked at a map of Spanish wine regions? If you have you will notice nothing around Madrid. It is not wine country. You need to move further south and in particular to the SE but it will be beyond any quick day via public transit.
Check out these tour offerings from one of Rick's most charming guides: http://www.madridtandt.com/tours-all/. The all-day winery excursion is more expensive, but both that and the in-city tastings are designed for your size of group.
Alsa Bus (www.alsa.es) can take you to a town like Aranda de Duero in 2 hours each way, but I don't know how worthwhile that destination might be. See also http://www.rutadelvinoriberadelduero.es/en/downloads.
@nivemalik... excuse me meddling into this conversation with a proposal that has nothing to do with wines but which is far easier to do from Madrid and equally satisfying.... do you like meat, pork in particular?... Madrid is close enough to Segovia by train (http://www.renfe.com/) --just 30' on a fast train-- you might want to explore an escapade to one of the areas which are famous for having the best-roasted suckling pig anywhere -and being as well a great example of a typical Castillian medieval city, with some notable highlights, such as the magnificent Gothic Cathedral as well as a very well preserved aqueduct from its Roman past.
Found these blog posts that might give you some hints:
https://victortravelblog.com/2013/05/13/cochinillo-asado-in-segovia/
http://blogs.barrons.com/penta/2013/10/18/travel-segovia-spain/
https://wine4food.com/food/a-sublime-pig-out-in-segovia-spain-one-of-my-ten-great-meals-of-2014/
And for more background on Segovia: http://visitsegovia.turismodesegovia.com/
Just food for thought :))
Adding to Enric's comments about tasty animals, the animal products, including butter, cheese, and ice cream there in Castile are also worth your indulgence. High pastureland like Switzerland with better temperatures!