I am having trouble understanding sacrifice fly and sacrifice bunt in baseball. Specifically, do both result in out for the batter? Because otherwise what would "sacrifice" mean? It will be great if one can explain these two terms.
These are both covered by MLB Rule 9.08:
The Official Scorer shall:
(a) Score a sacrifice bunt when, before two are out, the batter advances one or more runners with a bunt and is put out at first base
(d) Score a sacrifice fly when, before two are out, the batter hits a ball in flight handled by an outfielder or an infielder running in the outfield in fair or foul territory that [...] is caught, and a runner scores after the catch
So essentially you're correct: a sacrifice is something where the batter is out, but produces a secondary advantage for the batting team - either advancing a runner in the case of a sacrifice bunt, or scoring a runner in the case of a sacrifice fly.
The important detail here is likely that this is a detail only of scoring - it does not have any meaning on the field itself.
When the bunt or fly occurs, it is just like any other fly ball or bunt; the batter-runner is called out, and the runner presumably advances or scores.
The difference is that the scorer then rules it a sacrifice, and does not count it at as an "at bat" for scoring purposes. That means, it does not count against the batter's batting average. More detail about the history of the sacrifice hit (the generic term for both of these) can be found on baseball reference.
It is important to note that this only affects batting average, and advanced statistics do not give any credit to "sacrifices". It does count against OBP, for example, as that has no exceptions - it is simply (number of times the batter reaches base safely without an error or fielder's choice) / (number of times the batter stepped up to home plate and completed the plate appearance).
Also important to note that a sacrifice does not require an out. A sacrifice is also assigned when a batter-runner would have been out, but for a fielder's choice or an error - such as if they bunt and the fielder attempts to get the lead runner out (but fails).