How do I calculate the amount of money I get from an investor and the percentage I give him in return? Let's say I owe a company.

At the final state I want to be left with 1M cash for myself and 50 percent of the company.

The investor is not willing to buy shares and give me the money but only invest in the company.

I thought about selling my shares to a third person for one million cash after the first investment so I'll be left with 50% at the end and 1M.

How much percentage should I give the investor and for how much money, and how much should I sell to the third person and for how much money in order to be left with 1M and 50% of the company?
Well basically it pretty easy to calculate:

A + B + C = X

A:  0.25X : 25% of the company for investors

B:  0.5X : 50% you want to be left with

C:  1M : The price for selling to third party

X:  The value of the company that we would like to find

So in your case it's:

0.25X + 0.5X + 1M = X ->
0.25X = 1M -> 
X = 4