You are not going to void your warranty by carefully and correctly changing the RAM or HDD to something that is compatible with your machine. And by compatible, I mean in terms of runs at the same voltage, draws the same power, stuff like that. So just buy your stuff from a known brand, like Crucial, Kingston, Samsung, etc.
The only way you are going to void your warranty is if you do it in an unsafe environment (static charged, in the rain, etc.), if you're not at all careful (i.e. drop tools on the exposed innards, etc.) or if you ignore the instructions (ie. don't unclip the RAM or HDD and break a clip or SATA cable).
ie, if you're not a stupid clumsy oaf, you'll be fine.
And keep the old components in a safe place, in a static bag. For example, pack the old bits in the packaging that comes with the new stuff. If you ever have a problem, and Apple decides they don't like your upgrades, just switch them back to show them it still needs fixing, even in its original configuration.