Just based on your post
(a) assuming that you are a "resident for tax purposes" i.e. have met the substantial presence test, you are taxed same as a US citizen. Investment income is generally passive income -- interest, dividend etc. Real-estate investment (while passive ) is taxed only when disposed off or when it produces income -- thus if you buy a property and use it as your main or secondary home, there is no taxes till dispose off the prop and even then there may gain exclusion ( no losses allowed/ recognized); if on the other hand you acquire real-estate and use it for income generation, you are taxed only on the net gain and losses are allowed and gains are taxed at disposal.
(b) when you leave and go back to your country, you automatically become a Non-Resident Alien, taxed only on your US sourced / connected income. In such a situation you report on form 1040-NR and are taxed at a flat rate ( but you pay no FICA taxes ---- social security & medicare , 15.3% total ).
Does this help or do you need more detailed explanation ? If you do need more then you need to answer 1. which country are you from ( for treaty considerations ); 2. do you plan to go back or stay in the USA for the foreseeable future; (3) income property investment or buying a home that you will use for yourself etc. etc.