Let's suppose a batsman comes out of the crease and tries to hit the ball and loses grip on the bat and the bat flies and the batsman is outside the crease? Is this out? If yes, who gets the wicket? Has this ever happened in international cricket?
Based on your comments, nothing happens. The ball goes dead, he walks out and gets the bat, and the next ball is bowled.
Simply losing control of the bat does not cause a dismissal. And even if the ball hits the bat in the air and flies to a fielder, he is not out, as he needs to be holding the bat for it to be a dismissal.
Your question is quite unclear about the position of a batsman while he loses his bat.
But considering that he is taking a run and throws his bat inside the crease when he cannot reach before being run-out, he should be judged out because by rules, some part of the body or an equipment attached to the body should be behind the crease(dragged on the crease, not hanging in the air.) at the time the keeper/fielder removes the bails from the wicket.
Same case applies in case the batsman steps out to hit a ball, but the bat slips out of his hand and falls inside the crease while he is outside the crease and the keeper dislodges the bails.