So to optimize space I recently got the compact dell optiplex 7040 and unfortunately it only has 4 gb ram and obviously that is not enough. What can I do to increase that to say 8 or preferably 16 gb. And also what can I do to increase storage in the best way
You want to start here at this link: http://www.dell.com/us/business/p/optiplex-7040-micro-desktop/pd
This will help you to see what the model is designed to support.
If this is the correct model, it looks as if it will support 8 GB of RAM but only in a single stick format, as RAM goes. So don't be fooled by 16GB of SODIMM which is not the same.
It looks like it will take a conventional 2.5" drive larger than your current capacity.. I would recommend you stick with 7200 RPM for performance. Ideally, you could possibly for an 2.5" SSD. Conventional will be cheaper than the SSD. The SSD will offer better performance.